/// <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; }
/// <summary> /// Creates a slave peer that will attach itself to a master peer. /// </summary> /// <param name="parent">The parent peer.</param> /// <param name="peerId">The ID of this peer.</param> /// <param name="keyPair">The key pair or null.</param> public PeerCreator(PeerCreator parent, Number160 peerId, KeyPair keyPair) { parent._childConnections.Add(this); ConnectionBean = parent.ConnectionBean; PeerBean = new PeerBean(keyPair); PeerAddress self = parent.PeerBean.ServerPeerAddress.ChangePeerId(peerId); PeerBean.SetServerPeerAddress(self); _master = false; }