上一篇读到AppInit函数123行: InitParameterInteraction()函数,这个函数再src/init.cpp中实现,通过参数初始化设置网络参数
1,首先解析-bind,-whitebind参数,如果设置了这两个参数,-listen将设为true,允许监听接受外部连接,即使后面设置了-connect或者-proxy参数都会监听绑定的地址
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
if (gArgs.IsArgSet("-bind")) {
if (gArgs.SoftSetBoolArg("-listen", true))
LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
}
if (gArgs.IsArgSet("-whitebind")) {
if (gArgs.SoftSetBoolArg("-listen", true))
LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
}
2、-connect参数是用来只连接信任的节点,如果设置了-connect参数,-dnsseed和-listen将被设置为false,不允许监听请求并且不通过dns种子随机发现网络中的节点
if (gArgs.IsArgSet("-connect")) {
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
if (gArgs.SoftSetBoolArg("-dnsseed", false))
LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
if (gArgs.SoftSetBoolArg("-listen", false))
LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
}
3,-proxy则是设置代理服务器,
如果设置了这个参数则禁用监听,设置-listen为false。
设置-upnp为false, 使用全局即插即用(UPNP)映射监听端口,UPnP关闭时,你的节点仍将连接到比特币网络上其他的8个对等节点,接受新区块及交易。然而,它不会接受来自其他对等节点进来的连接,除非你手动启用你路由器上的端口转发。
同时设置-discover为false,-discover表示是否希望网络中的其他节点发现自己的地址,如果设置了代理,自然这里应设为false。
if (gArgs.IsArgSet("-proxy")) {
// to protect privacy, do not listen by default if a default proxy server is specified
if (gArgs.SoftSetBoolArg("-listen", false))
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
// to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
// to listen locally, so don't rely on this happening through -listen below.
if (gArgs.SoftSetBoolArg("-upnp", false))
LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
// to protect privacy, do not discover addresses by default
if (gArgs.SoftSetBoolArg("-discover", false))
LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
}
4,如果没有设置监听,则设置-upnp,-discover,-listenonion参数为false,-listennonion表示匿名地址监听。
if (!gArgs.GetBoolArg("-listen", DEFAULT_LISTEN)) {
// do not map ports or try to retrieve public IP when not listening (pointless)
if (gArgs.SoftSetBoolArg("-upnp", false))
LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
if (gArgs.SoftSetBoolArg("-discover", false))
LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
if (gArgs.SoftSetBoolArg("-listenonion", false))
LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
}
5,这个-externalip表示指定公有地址,也就是从指定的公有地址同步区块信息以及广播交易信息等等,所有的消息都只发向指定的公有地址,并且不寻找其他的地址
if (gArgs.IsArgSet("-externalip")) {
// if an explicit public IP is specified, do not try to find others
if (gArgs.SoftSetBoolArg("-discover", false))
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
}
6,如果-blocksonly设置为true,-blocksonly表示只接受打包区块,DEFAULT_BLOCKSONLY默认值为false,禁用-whitelistrelay,表示不接受从白名单中的节点转发过来的交易。
// disable whitelistrelay in blocksonly mode
if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
if (gArgs.SoftSetBoolArg("-whitelistrelay", false))
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0\n", __func__);
}
7,如果设置-whitelistforcerelay为true,表示强制转发从白名单中继过来的交易信息,则设置-whitelistrelay为true
// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
if (gArgs.SoftSetBoolArg("-whitelistrelay", true))
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
}
8,-blockmaxsize这个参数已经被-blockmaxweight取代,隔离见证中区块尺寸大小的概念被区块重量取代,参考https://en.bitcoin.it/wiki/Weight_units,WITNESS_SCALE_FACTOR 常量在src/consensus/consensus.h定义,static const int WITNESS_SCALE_FACTOR = 4;
if (gArgs.IsArgSet("-blockmaxsize")) {
unsigned int max_size = gArgs.GetArg("-blockmaxsize", 0);
if (gArgs.SoftSetArg("blockmaxweight", strprintf("%d", max_size * WITNESS_SCALE_FACTOR))) {
LogPrintf("%s: parameter interaction: -blockmaxsize=%d -> setting -blockmaxweight=%d (-blockmaxsize is deprecated!)\n", __func__, max_size, max_size * WITNESS_SCALE_FACTOR);
} else {
LogPrintf("%s: Ignoring blockmaxsize setting which is overridden by blockmaxweight", __func__);
}
}
}
来源:CSDN
作者:ruiyiin
链接:https://blog.csdn.net/ruiyiin/article/details/104633275