public async ValueTask AttachAsync(IPeerContext peerContext) { PeerContext = peerContext as ExamplePeerContext ?? throw new ArgumentException("Expected ExamplePeerContext", nameof(peerContext)); _messageWriter = PeerContext.GetMessageWriter(); await OnPeerAttachedAsync().ConfigureAwait(false); }
/// <summary>Initializes a new instance of the <see cref="BaseProcessor"/> class.</summary> /// <param name="logger">The logger.</param> /// <param name="eventBus">The event bus.</param> /// <param name="peerBehaviorManager">The peer behavior manager.</param> /// <param name="isHandshakeAware">If set to <c>true</c> register the instance to be handshake aware: when the peer is handshaked, OnPeerHandshaked method will be invoked.</param> public BaseProcessor(ILogger <BaseProcessor> logger, IEventBus eventBus, IPeerBehaviorManager peerBehaviorManager, bool isHandshakeAware) { this.logger = logger; this.eventBus = eventBus; _peerBehaviorManager = peerBehaviorManager; _isHandshakeAware = isHandshakeAware; PeerContext = null !; //hack to not rising null warnings, these are initialized when calling AttachAsync _messageWriter = null !; //hack to not rising null warnings, these are initialized when calling AttachAsync }
public NetworkPeerContext(ILogger logger, IEventBus eventBus, PeerConnectionDirection direction, string peerId, EndPoint localEndPoint, EndPoint publicEndPoint, EndPoint remoteEndPoint, INetworkMessageWriter messageWriter) : base(logger, eventBus, direction, peerId, localEndPoint, publicEndPoint, remoteEndPoint, messageWriter) { }
public override IPeerContext CreateIncomingPeerContext( string peerId, EndPoint localEndPoint, EndPoint remoteEndPoint, INetworkMessageWriter messageWriter) { var peerContext = (NetworkPeerContext)base.CreateIncomingPeerContext(peerId, localEndPoint, remoteEndPoint, messageWriter); // At this point we can enrich the context from the DI return(peerContext); }
public override IPeerContext CreateOutgoingPeerContext( string peerId, EndPoint localEndPoint, OutgoingConnectionEndPoint outgoingConnectionEndPoint, INetworkMessageWriter messageWriter) { var peerContext = (NetworkPeerContext)base.CreateOutgoingPeerContext(peerId, localEndPoint, outgoingConnectionEndPoint, messageWriter); // At this point we can enrich the context from the DI return(peerContext); }
public PeerContext(ILogger logger, IEventBus eventBus, PeerConnectionDirection direction, string peerId, EndPoint localEndPoint, EndPoint publicEndPoint, EndPoint remoteEndPoint, INetworkMessageWriter messageWriter) { this.logger = logger; this.eventBus = eventBus; Direction = direction; PeerId = peerId; this.messageWriter = messageWriter; LocalEndPoint = localEndPoint.AsIPEndPoint(); PublicEndPoint = publicEndPoint.AsIPEndPoint(); RemoteEndPoint = remoteEndPoint.AsIPEndPoint(); }
protected virtual IPeerContext Create(PeerConnectionDirection direction, string peerId, EndPoint localEndPoint, EndPoint remoteEndPoint, INetworkMessageWriter messageWriter) { var peerContext = (TPeerContext)System.Activator.CreateInstance(typeof(TPeerContext), _loggerFactory.CreateLogger <IPeerContext>(), _eventBus, direction, peerId, localEndPoint, GetPublicEndPoint(localEndPoint), remoteEndPoint, messageWriter ) !; return(peerContext); }
public abstract void SerializeToNetworkMessage(INetworkMessageWriter networkMessage);
public override IPeerContext CreateOutgoingPeerContext(string peerId, EndPoint localEndPoint, OutgoingConnectionEndPoint outgoingConnectionEndPoint, INetworkMessageWriter messageWriter) { //we know the returned type is correct because we specified it in our inheritance PeerContextFactory<ExamplePeerContext> var peerContext = (ExamplePeerContext)base.CreateOutgoingPeerContext(peerId, localEndPoint, outgoingConnectionEndPoint, messageWriter); /// outgoing PeerContext has a feature of type <see cref="OutgoingConnectionEndPoint"/> that we use to store additional information /// for peers we want to connect to (e.g. we could store a public key of the peer to start an encrypted communication. /// Since this information may be important to us, we decide to have an explicit property in our <see cref="ExamplePeerContext"/> so we can /// access that information easily in our code. /// Note that we set that information in our <see cref="Client.ExampleRequiredConnection"/> connector. string myExtraInformation = (string)peerContext.Features.Get <OutgoingConnectionEndPoint>().Items[nameof(ExampleEndPoint.MyExtraInformation)]; peerContext.MyExtraInformation = myExtraInformation; return(peerContext); }
public virtual IPeerContext CreateOutgoingPeerContext(string peerId, EndPoint localEndPoint, OutgoingConnectionEndPoint outgoingConnectionEndPoint, INetworkMessageWriter messageWriter) { IPeerContext peerContext = Create(PeerConnectionDirection.Outbound, peerId, localEndPoint, outgoingConnectionEndPoint.EndPoint, messageWriter); peerContext.Features.Set(outgoingConnectionEndPoint); return(peerContext); }
public virtual IPeerContext CreateIncomingPeerContext(string peerId, EndPoint localEndPoint, EndPoint remoteEndPoint, INetworkMessageWriter messageWriter) { return(Create(PeerConnectionDirection.Inbound, peerId, localEndPoint, remoteEndPoint, messageWriter)); }