Exemple #1
0
        public async Task <INetworkStream> NewStream(PeerId peer, IEnumerable <ProtocolId> protocols, CancellationToken cancellationToken)
        {
            var pref = PreferredProtocol(peer, protocols);

            if (pref != "")
            {
                return(await NewStream(peer, pref, cancellationToken));
            }

            var protosstrs = protocols.Select(p => p.ToString()).ToArray();

            var s = await Network.NewStreamAsync(peer, cancellationToken);

            if (s == null)
            {
                return(null);
            }

            var selected = await MultistreamMuxer.SelectOneOfAsync(protosstrs, ((IReadWriter)s).AsSystemStream(), cancellationToken);

            if (selected == null)
            {
                s.Dispose();
                return(null);
            }

            s.Protocol = new ProtocolId(selected);
            Peerstore.AddProtocols(peer, selected);

            //reporter

            return(s);
        }
Exemple #2
0
        private async Task DialPeer(PeerId peer, CancellationToken cancellationToken)
        {
            var c = await Network.DialPeerAsync(peer, cancellationToken);

            if (c == null)
            {
                return;
            }

            Peerstore.AddProtocols(peer);

            await Task.Factory.StartNew(() => _ids.IdentifyConnection(c), cancellationToken);
        }
Exemple #3
0
 private void NewConnectionHandler(INetworkConnection connection)
 {
     Peerstore.AddProtocols(connection.RemotePeer);
     _ids.IdentifyConnection(connection);
 }