@@ -28,53 +28,56 @@ cd packages/server
2828*/
2929
3030import type { ConnectionStats , ServerInfo } from "./types" ;
31+
32+ import { delay } from "awaiting" ;
33+ import { EventEmitter } from "events" ;
34+ import { throttle } from "lodash" ;
35+ import { Server } from "socket.io" ;
36+
37+ import { getClientIpAddress } from "@cocalc/util/get-client-ip-address" ;
38+ import { getLogger } from "@cocalc/conat/client" ;
39+ import { UsageMonitor } from "@cocalc/conat/monitor/usage" ;
40+ import { type ConatSocketServer } from "@cocalc/conat/socket" ;
3141import {
3242 isValidSubject ,
3343 isValidSubjectWithoutWildcards ,
3444} from "@cocalc/conat/util" ;
35- import { Server } from "socket.io" ;
36- import { delay } from "awaiting" ;
45+ import { once , until } from "@cocalc/util/async-utils" ;
46+ import { is_array } from "@cocalc/util/misc" ;
47+ import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
48+ import { Metrics } from "../types" ;
3749import {
38- ConatError ,
39- connect ,
4050 Client ,
4151 type ClientOptions ,
52+ ConatError ,
53+ connect ,
4254 MAX_INTEREST_TIMEOUT ,
4355 STICKY_QUEUE_GROUP ,
4456} from "./client" ;
45- import {
46- RESOURCE ,
47- MAX_CONNECTIONS_PER_USER ,
48- MAX_CONNECTIONS ,
49- MAX_PAYLOAD ,
50- MAX_SUBSCRIPTIONS_PER_CLIENT ,
51- MAX_SUBSCRIPTIONS_PER_HUB ,
52- } from "./constants" ;
53- import { Patterns } from "./patterns" ;
54- import { is_array } from "@cocalc/util/misc" ;
55- import { UsageMonitor } from "@cocalc/conat/monitor/usage" ;
56- import { once , until } from "@cocalc/util/async-utils" ;
5757import {
5858 clusterLink ,
5959 type ClusterLink ,
6060 clusterStreams ,
6161 type ClusterStreams ,
62- trimClusterStreams ,
6362 createClusterPersistServer ,
64- Sticky ,
65- Interest ,
6663 hashInterest ,
6764 hashSticky ,
65+ Interest ,
66+ Sticky ,
67+ trimClusterStreams ,
6868} from "./cluster" ;
69- import { type ConatSocketServer } from "@cocalc/conat/socket" ;
70- import { throttle } from "lodash" ;
71- import { getLogger } from "@cocalc/conat/client" ;
72- import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
73- import { type SysConatServer , sysApiSubject , sysApi } from "./sys" ;
69+ import {
70+ MAX_CONNECTIONS ,
71+ MAX_CONNECTIONS_PER_USER ,
72+ MAX_PAYLOAD ,
73+ MAX_SUBSCRIPTIONS_PER_CLIENT ,
74+ MAX_SUBSCRIPTIONS_PER_HUB ,
75+ RESOURCE ,
76+ } from "./constants" ;
77+ import { Patterns } from "./patterns" ;
7478import { forkedConatServer } from "./start-server" ;
7579import { stickyChoice } from "./sticky" ;
76- import { EventEmitter } from "events" ;
77- import { Metrics } from "../types" ;
80+ import { sysApi , sysApiSubject , type SysConatServer } from "./sys" ;
7881
7982const logger = getLogger ( "conat:core:server" ) ;
8083
@@ -1755,27 +1758,7 @@ export function randomChoice(v: Set<string>): string {
17551758
17561759// See https://socket.io/how-to/get-the-ip-address-of-the-client
17571760function getAddress ( socket ) {
1758- const header = socket . handshake . headers [ "forwarded" ] ;
1759- if ( header ) {
1760- for ( const directive of header . split ( "," ) [ 0 ] . split ( ";" ) ) {
1761- if ( directive . startsWith ( "for=" ) ) {
1762- return directive . substring ( 4 ) ;
1763- }
1764- }
1765- }
1766-
1767- let addr = socket . handshake . headers [ "x-forwarded-for" ] ?. split ( "," ) ?. [ 0 ] ;
1768- if ( addr ) {
1769- return addr ;
1770- }
1771- for ( const other of [ "cf-connecting-ip" , "fastly-client-ip" ] ) {
1772- addr = socket . handshake . headers [ other ] ;
1773- if ( addr ) {
1774- return addr ;
1775- }
1776- }
1777-
1778- return socket . handshake . address ;
1761+ return getClientIpAddress ( socket . handshake ) ?? socket . handshake . address ;
17791762}
17801763
17811764export function updateInterest (
0 commit comments