/**
* <p>Creates a PeerGroup for the given network and chain, using the provided Netty {@link ClientBootstrap} object.
* </p>
*
* <p>A ClientBootstrap creates raw (TCP) connections to other nodes on the network. Normally you won't need to
* provide one - use the other constructors. Providing your own bootstrap is useful if you want to control
* details like how many network threads are used, the connection timeout value and so on. To do this, you can
* use {@link PeerGroup#createClientBootstrap()} method and then customize the resulting object. Example:</p>
*
* <pre>
* ClientBootstrap bootstrap = PeerGroup.createClientBootstrap();
* bootstrap.setOption("connectTimeoutMillis", 3000);
* PeerGroup peerGroup = new PeerGroup(params, chain, bootstrap);
* </pre>
*
* <p>The ClientBootstrap provided does not need a channel pipeline factory set. If one wasn't set, the provided
* bootstrap will be modified to have one that sets up the pipelines correctly.</p>
*/
public PeerGroup(NetworkParameters params, AbstractBlockChain chain, ClientBootstrap bootstrap) {
this.params = params;
this.chain = chain; // Can be null.
this.fastCatchupTimeSecs = params.genesisBlock.getTimeSeconds();
this.wallets = new CopyOnWriteArrayList<Wallet>();
// This default sentinel value will be overridden by one of two actions:
// - adding a peer discovery source sets it to the default
// - using connectTo() will increment it by one
this.maxConnections = 0;
int height = chain == null ? 0 : chain.getBestChainHeight();
// We never request that the remote node wait for a bloom filter yet, as we have no wallets
this.versionMessage = new VersionMessage(params, height, true);
memoryPool = new MemoryPool();
// Configure Netty. The "ClientBootstrap" creates connections to other nodes. It can be configured in various
// ways to control the network.
if (bootstrap == null) {
this.bootstrap = createClientBootstrap();
this.bootstrap.setPipelineFactory(makePipelineFactory(params, chain));
} else {
this.bootstrap = bootstrap;
}
inactives = Collections.synchronizedList(new ArrayList<PeerAddress>());
peers = new ArrayList<Peer>();
pendingPeers = new ArrayList<Peer>();
channels = new DefaultChannelGroup();
peerDiscoverers = new CopyOnWriteArraySet<PeerDiscovery>();
peerEventListeners = new CopyOnWriteArrayList<PeerEventListener>();
}
PeerGroup.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:NithPointsj
作者:
评论列表
文章目录