上一篇讀到AppInit函數(shù)123行: InitParameterInteraction()函數(shù),這個(gè)函數(shù)再src/init.cpp中實(shí)現(xiàn),通過(guò)參數(shù)初始化設(shè)置網(wǎng)絡(luò)參數(shù)
1篓像,首先解析-bind,-whitebind參數(shù),如果設(shè)置了這兩個(gè)參數(shù)魁蒜,-listen將設(shè)為true昔案,允許監(jiān)聽接受外部連接,即使后面設(shè)置了-connect或者-proxy參數(shù)都會(huì)監(jiān)聽綁定的地址
// 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參數(shù)是用來(lái)只連接信任的節(jié)點(diǎn),如果設(shè)置了-connect參數(shù),-dnsseed和-listen將被設(shè)置為false个少,不允許監(jiān)聽請(qǐng)求并且不通過(guò)dns種子隨機(jī)發(fā)現(xiàn)網(wǎng)絡(luò)中的節(jié)點(diǎn)
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則是設(shè)置代理服務(wù)器,
如果設(shè)置了這個(gè)參數(shù)則禁用監(jiān)聽洪乍,設(shè)置-listen為false。
設(shè)置-upnp為false, 使用全局即插即用(UPNP)映射監(jiān)聽端口夜焦,UPnP關(guān)閉時(shí)壳澳,你的節(jié)點(diǎn)仍將連接到比特幣網(wǎng)絡(luò)上其他的8個(gè)對(duì)等節(jié)點(diǎn),接受新區(qū)塊及交易茫经。然而巷波,它不會(huì)接受來(lái)自其他對(duì)等節(jié)點(diǎn)進(jìn)來(lái)的連接,除非你手動(dòng)啟用你路由器上的端口轉(zhuǎn)發(fā)卸伞。
同時(shí)設(shè)置-discover為false抹镊,-discover表示是否希望網(wǎng)絡(luò)中的其他節(jié)點(diǎn)發(fā)現(xiàn)自己的地址,如果設(shè)置了代理荤傲,自然這里應(yīng)設(shè)為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,如果沒有設(shè)置監(jiān)聽,則設(shè)置-upnp,-discover,-listenonion參數(shù)為false遂黍,-listennonion表示匿名地址監(jiān)聽终佛。
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,這個(gè)-externalip表示指定公有地址,也就是從指定的公有地址同步區(qū)塊信息以及廣播交易信息等等雾家,所有的消息都只發(fā)向指定的公有地址铃彰,并且不尋找其他的地址
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設(shè)置為true,-blocksonly表示只接受打包區(qū)塊芯咧,DEFAULT_BLOCKSONLY默認(rèn)值為false牙捉,禁用-whitelistrelay妹田,表示不接受從白名單中的節(jié)點(diǎn)轉(zhuǎn)發(fā)過(guò)來(lái)的交易。
// 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,如果設(shè)置-whitelistforcerelay為true,表示強(qiáng)制轉(zhuǎn)發(fā)從白名單中繼過(guò)來(lái)的交易信息,則設(shè)置-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這個(gè)參數(shù)已經(jīng)被-blockmaxweight取代,隔離見證中區(qū)塊尺寸大小的概念被區(qū)塊重量取代鹃共,參考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__);
}
}
}