@@ -28,49 +28,52 @@ 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} from "./client" ;
44- import {
45- RESOURCE ,
46- MAX_CONNECTIONS_PER_USER ,
47- MAX_CONNECTIONS ,
48- MAX_PAYLOAD ,
49- MAX_SUBSCRIPTIONS_PER_CLIENT ,
50- MAX_SUBSCRIPTIONS_PER_HUB ,
51- } from "./constants" ;
52- import { Patterns } from "./patterns" ;
53- import { is_array } from "@cocalc/util/misc" ;
54- import { UsageMonitor } from "@cocalc/conat/monitor/usage" ;
55- import { once , until } from "@cocalc/util/async-utils" ;
5656import {
5757 clusterLink ,
5858 type ClusterLink ,
5959 clusterStreams ,
6060 type ClusterStreams ,
61- trimClusterStreams ,
6261 createClusterPersistServer ,
62+ trimClusterStreams ,
6363 Interest ,
6464 hashInterest ,
6565} from "./cluster" ;
66- import { type ConatSocketServer } from "@cocalc/conat/socket" ;
67- import { throttle } from "lodash" ;
68- import { getLogger } from "@cocalc/conat/client" ;
69- import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
70- import { type SysConatServer , sysApiSubject , sysApi } from "./sys" ;
66+ import {
67+ MAX_CONNECTIONS ,
68+ MAX_CONNECTIONS_PER_USER ,
69+ MAX_PAYLOAD ,
70+ MAX_SUBSCRIPTIONS_PER_CLIENT ,
71+ MAX_SUBSCRIPTIONS_PER_HUB ,
72+ RESOURCE ,
73+ } from "./constants" ;
74+ import { Patterns } from "./patterns" ;
7175import { forkedConatServer } from "./start-server" ;
72- import { EventEmitter } from "events" ;
73- import { Metrics } from "../types" ;
76+ import { sysApi , sysApiSubject , type SysConatServer } from "./sys" ;
7477
7578const logger = getLogger ( "conat:core:server" ) ;
7679
@@ -1564,27 +1567,7 @@ export function randomChoice(v: Set<string>): string {
15641567
15651568// See https://socket.io/how-to/get-the-ip-address-of-the-client
15661569function getAddress ( socket ) {
1567- const header = socket . handshake . headers [ "forwarded" ] ;
1568- if ( header ) {
1569- for ( const directive of header . split ( "," ) [ 0 ] . split ( ";" ) ) {
1570- if ( directive . startsWith ( "for=" ) ) {
1571- return directive . substring ( 4 ) ;
1572- }
1573- }
1574- }
1575-
1576- let addr = socket . handshake . headers [ "x-forwarded-for" ] ?. split ( "," ) ?. [ 0 ] ;
1577- if ( addr ) {
1578- return addr ;
1579- }
1580- for ( const other of [ "cf-connecting-ip" , "fastly-client-ip" ] ) {
1581- addr = socket . handshake . headers [ other ] ;
1582- if ( addr ) {
1583- return addr ;
1584- }
1585- }
1586-
1587- return socket . handshake . address ;
1570+ return getClientIpAddress ( socket . handshake ) ?? socket . handshake . address ;
15881571}
15891572
15901573export function updateInterest ( update : InterestUpdate , interest : Interest ) {
0 commit comments