Add switching between Status beta and staging fleet

This commit is contained in:
kdeme 2019-11-05 13:47:47 +01:00 committed by zah
parent 4aee9fc7e8
commit 0f299842e1
5 changed files with 28 additions and 17 deletions

View File

@ -62,7 +62,7 @@ void NimMain();
* When privkey is null, a new keypair will be generated.
*/
bool nimbus_start(uint16_t port, bool startListening, bool enableDiscovery,
double minPow, uint8_t* privkey);
double minPow, uint8_t* privkey, bool staging);
/** Add peers to connect to - must be called after nimbus_start */
bool nimbus_add_peer(const char* nodeId);

View File

@ -109,8 +109,24 @@ proc subscribeChannel(
# except:
# notice "no luck parsing", message=getCurrentExceptionMsg()
proc setBootNodes(nodes: openArray[string]): seq[ENode] =
var bootnode: ENode
result = newSeqOfCap[ENode](nodes.len)
for nodeId in nodes:
# For now we can just do assert as we only pass our own const arrays.
doAssert(initENode(nodeId, bootnode) == ENodeStatus.Success)
result.add(bootnode)
proc connectToNodes(nodes: openArray[string]) =
for nodeId in nodes:
var whisperENode: ENode
# For now we can just do assert as we only pass our own const arrays.
doAssert(initENode(nodeId, whisperENode) == ENodeStatus.Success)
traceAsyncErrors node.peerPool.connectToNode(newNode(whisperENode))
proc nimbus_start(port: uint16, startListening: bool, enableDiscovery: bool,
minPow: float64, privateKey: ptr byte): bool {.exportc.} =
minPow: float64, privateKey: ptr byte, staging: bool): bool {.exportc.} =
# TODO: any async calls can still create `Exception`, why?
let address = Address(
udpPort: port.Port, tcpPort: port.Port, ip: parseIpAddress("0.0.0.0"))
@ -134,20 +150,15 @@ proc nimbus_start(port: uint16, startListening: bool, enableDiscovery: bool,
# var bloom: Bloom
# node.protocolState(Whisper).config.bloom = bloom
var bootnodes: seq[ENode] = @[]
for nodeId in MainnetBootnodes:
var bootnode: ENode
discard initENode(nodeId, bootnode)
bootnodes.add(bootnode)
let bootnodes = if staging: setBootNodes(StatusBootNodesStaging)
else: setBootNodes(StatusBootNodes)
traceAsyncErrors node.connectToNetwork(bootnodes, startListening, enableDiscovery)
# main network has mostly non SHH nodes, so we connect directly to SHH nodes
for nodeId in WhisperNodes:
var whisperENode: ENode
discard initENode(nodeId, whisperENode)
var whisperNode = newNode(whisperENode)
traceAsyncErrors node.connectToNetwork(bootnodes, startListening,
enableDiscovery)
traceAsyncErrors node.peerPool.connectToNode(whisperNode)
# Connect to known Status Whisper fleet directly
if staging: connectToNodes(WhisperNodesStaging)
else: connectToNodes(WhisperNodes)
result = true

View File

@ -22,7 +22,7 @@ int main(int argc, char* argv[]) {
time_t lastmsg;
NimMain();
nimbus_start(30303, true, false, 0.002, NULL);
nimbus_start(30303, true, false, 0.002, NULL, false);
nimbus_join_public_chat(channel, print_msg);

View File

@ -39,7 +39,7 @@ func receiveHandler(msg *C.received_message) {
func Start() {
C.NimMain()
fmt.Println("[nim-status] Start Nimbus")
C.nimbus_start(30306, true, false, 0.002, nil)
C.nimbus_start(30306, true, false, 0.002, nil, false)
peer1 := "enode://2d3e27d7846564f9b964308038dfadd4076e4373ac938e020708ad8819fd4fd90e5eb8314140768f782db704cb313b60707b968f8b61108a6fecd705b041746d@192.168.0.33:30303"
peer2 := "enode://4ea35352702027984a13274f241a56a47854a7fd4b3ba674a596cff917d3c825506431cf149f9f2312a293bb7c2b1cca55db742027090916d01529fe0729643b@206.189.243.178:443"

View File

@ -58,7 +58,7 @@ func Start() {
privKey := (*C.uint8_t)(C.CBytes(data))
defer C.free(unsafe.Pointer(privKey))
if C.nimbus_start(30306, true, false, 0.002, privKey) == false {
if C.nimbus_start(30306, true, false, 0.002, privKey, false) == false {
panic("Can't start nimbus")
}
}