コード例 #1
0
ファイル: PeerCreator.cs プロジェクト: lanicon/TomP2P.NET
        /// <summary>
        /// Creates a master peer and starts UDP and TCP channels.
        /// </summary>
        /// <param name="p2PId">The ID of the network.</param>
        /// <param name="peerId">The ID of this peer.</param>
        /// <param name="keyPair">The key pair or null.</param>
        /// <param name="channelServerConfiguration">The server configuration to create the
        /// channel server that is used for listening for incoming connections.</param>
        /// <param name="channelClientConfiguration">The client-side configuration.</param>
        /// <param name="timer"></param>
        public PeerCreator(int p2PId, Number160 peerId, KeyPair keyPair,
                           ChannelServerConfiguration channelServerConfiguration,
                           ChannelClientConfiguration channelClientConfiguration,
                           ExecutorService timer)
        {
            // peer bean
            PeerBean = new PeerBean(keyPair);
            PeerAddress self = FindPeerAddress(peerId, channelClientConfiguration, channelServerConfiguration);

            PeerBean.SetServerPeerAddress(self);
            Logger.Info("Visible address to other peers: {0}.", self);

            // start server
            var dispatcher    = new Dispatcher(p2PId, PeerBean, channelServerConfiguration.HearBeatMillis);
            var channelServer = new ChannelServer(channelServerConfiguration, dispatcher, PeerBean.PeerStatusListeners);

            if (!channelServer.Startup())
            {
                ShutdownNetty();
                throw new IOException("Cannot bind to TCP or UDP port.");
            }

            // connection bean
            var sender      = new Sender(peerId, PeerBean.PeerStatusListeners, channelClientConfiguration, dispatcher);
            var reservation = new Reservation(channelClientConfiguration);

            ConnectionBean = new ConnectionBean(p2PId, dispatcher, sender, channelServer, reservation, channelClientConfiguration, timer);
            _master        = true;
        }
コード例 #2
0
ファイル: ChannelServer.cs プロジェクト: lanicon/TomP2P.NET
        /// <summary>
        /// Sets parameters and starts network device discovery.
        /// </summary>
        /// <param name="channelServerConfiguration">The server configuration that contains e.g. the handlers</param>
        /// <param name="dispatcher">The shared dispatcher.</param>
        /// <param name="peerStatusListeners">The status listeners for offline peers.</param>
        public ChannelServer(ChannelServerConfiguration channelServerConfiguration, Dispatcher dispatcher,
                             IList <IPeerStatusListener> peerStatusListeners)
        {
            ChannelServerConfiguration = channelServerConfiguration;
            _interfaceBindings         = channelServerConfiguration.BindingsIncoming;
            _dispatcher          = dispatcher;
            _peerStatusListeners = peerStatusListeners;
            string status = DiscoverNetworks.DiscoverInterfaces(_interfaceBindings);

            Logger.Info("Status of interface search: {0}.", status);

            _tcpDropConnectionInboundHandler = new DropConnectionInboundHandler(channelServerConfiguration.MaxTcpIncomingConnections);
            _udpDropConnectionInboundHandler = new DropConnectionInboundHandler(channelServerConfiguration.MaxUdpIncomingConnections);
            _udpDecoderHandler = new TomP2PSinglePacketUdp(channelServerConfiguration.SignatureFactory);
            _tcpDecoderHandler = new TomP2PCumulationTcp(channelServerConfiguration.SignatureFactory);
            _encoderHandler    = new TomP2POutbound(false, channelServerConfiguration.SignatureFactory);
        }
コード例 #3
0
ファイル: PeerBuilder.cs プロジェクト: pacificIT/TomP2P.NET
 public PeerBuilder SetChannelServerConfiguration(ChannelServerConfiguration channelServerConfiguration)
 {
     ChannelServerConfiguration = channelServerConfiguration;
     return this;
 }
コード例 #4
0
ファイル: PeerCreator.cs プロジェクト: lanicon/TomP2P.NET
        /// <summary>
        /// Creates the peer address based on the network discovery that was done./>
        /// </summary>
        /// <param name="peerId">The ID of this peer.</param>
        /// <param name="channelClientConfiguration"></param>
        /// <param name="channelServerConfiguration"></param>
        /// <returns>The peer address of this peer.</returns>
        private static PeerAddress FindPeerAddress(Number160 peerId,
                                                   ChannelClientConfiguration channelClientConfiguration, ChannelServerConfiguration channelServerConfiguration)
        {
            string status = DiscoverNetworks.DiscoverInterfaces(channelClientConfiguration.BindingsOutgoing);

            Logger.Info("Status of external address search: " + status);

            IPAddress outsideAddress = channelClientConfiguration.BindingsOutgoing.FoundAddress;

            if (outsideAddress == null)
            {
                throw new IOException("Not listening to anything. Maybe the binding information is wrong.");
            }

            var peerSocketAddress = new PeerSocketAddress(outsideAddress,
                                                          channelServerConfiguration.Ports.TcpPort,
                                                          channelServerConfiguration.Ports.UdpPort);

            var self = new PeerAddress(peerId, peerSocketAddress,
                                       channelServerConfiguration.IsBehindFirewall,
                                       channelServerConfiguration.IsBehindFirewall,
                                       false, PeerAddress.EmptyPeerSocketAddresses);

            return(self);
        }