Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
 /// <summary>
 /// The connection bean with unmodifiable objects. Once it is set, it cannot be changed.
 /// If it is required to change, then the peer must be shut down and a new one created.
 /// </summary>
 /// <param name="p2PId">The P2P ID.</param>
 /// <param name="dispatcher">The dispatcher object that receives all messages.</param>
 /// <param name="sender">The sender object that sends out messages.</param>
 /// <param name="channelServer">The channel server that listens on incoming connections.</param>
 /// <param name="reservation">The connection reservation that is responsible for resource management.</param>
 /// <param name="resourceConfiguration">The configuration that is responsible for the resource numbers.</param>
 /// <param name="timer">The timer for the discovery process.</param>
 public ConnectionBean(int p2PId, Dispatcher dispatcher, Sender sender, ChannelServer channelServer,
                       Reservation reservation, ChannelClientConfiguration resourceConfiguration, ExecutorService timer)
 {
     P2PId                 = p2PId;
     Dispatcher            = dispatcher;
     Sender                = sender;
     ChannelServer         = channelServer;
     Reservation           = reservation;
     ResourceConfiguration = resourceConfiguration;
     Timer                 = timer;
 }