public void SetPeerContext(IPeerContext peerContext) { _networkPeerContext = peerContext as NetworkPeerContext ?? throw new ArgumentException("Expected NetworkPeerContext", nameof(peerContext));; _deserializationContext.SetInitiator(_networkPeerContext.Direction == PeerConnectionDirection.Outbound); LightningEndpoint?lightningEndpoint = null; if (peerContext.Direction == PeerConnectionDirection.Outbound) { OutgoingConnectionEndPoint endpoint = peerContext.Features.Get <OutgoingConnectionEndPoint>(); if (endpoint == null || !endpoint.Items.TryGetValue(nameof(LightningEndpoint), out object?res)) { _logger.LogError("Remote connection was not found "); throw new ApplicationException("Initiator connection must have a public key of the remote node"); } if (res == null) { _logger.LogError("Remote connection type is invalid"); throw new ApplicationException("Remote connection type is invalid"); } lightningEndpoint = (LightningEndpoint)res; } _handshakeProtocol = new HandshakeWithNoiseProtocol(_nodeContext, lightningEndpoint?.NodePubKey, _handshakeProcessor); _networkPeerContext.SetHandshakeProtocol(_handshakeProtocol); }