import { BitField } from "@node-lightning/core" ; import { ILogger } from "@node-lightning/logger" ; import { NoiseSocket } from "@node-lightning/noise" ; import { NoiseServer } from "@node-lightning/noise" ; import { EventEmitter } from "events" ; import { InitFeatureFlags } from "./flags/InitFeatureFlags" ; import { Peer } from "./Peer" ; export class PeerServer extends EventEmitter { protected _server : NoiseServer ; constructor ( readonly host , readonly port , readonly localSecret , readonly localFeatures , readonly localChains , readonly logger ) { super ( ) ; this . _server = new NoiseServer ( { ls : localSecret } , this . _onSocket . bind ( this ) ) ; this . _server . on ( "listening" , ( ) => this . emit ( "listening" ) ) ; } param host param port public listen ( ) { this . _server . listen ( { host : this . host , port : this . port } ) ; } /**
     * Shuts down the server
     */ public shutdown ( ) { this . _server . close ( ) ; } param socket protected _onSocket ( socket ) { this . logger . info ( "peer connected" ) ; const peer = new Peer ( this . localSecret , this . localFeatures , this . localChains , this . logger ) ; peer . attach ( socket ) ; this . emit ( "peer" , peer ) ; } }