func (bitverseObserver *BitverseObserver) OnConnected(node *bitverse.EdgeNode, remoteNode *bitverse.RemoteNode) { fmt.Println("-> now connected to super node " + remoteNode.Id()) remoteNode.SendChildrenRequest() msgService := node.GetMsgService(serviceId) msgService.SendAndGetReply("6a133a1b41f987210559ceb4ed9b1dbf58aec876", "hello", 10, func(err error, reply interface{}) { if err == nil { fmt.Println("that was a surprise " + reply.(string)) } else { // we will most likely timeout unless node 6a133a1b41f987210559ceb4ed9b1dbf58aec876 is online fmt.Println("failed to send message to node with id 6a133a1b41f987210559ceb4ed9b1dbf58aec876") } }) }
func (bitverseObserver *BitverseObserver) OnSiblingJoined(node *bitverse.EdgeNode, id string) { fmt.Println("-> sibling " + id + " joined") msgService := node.GetMsgService(serviceId) msgService.Send(id, "hello") fmt.Println("sending: hello") fmt.Println("sending: who are you?") msgService.SendAndGetReply(id, "who are you?", 10, func(err error, reply interface{}) { if err == nil { fmt.Println("got a reply (who are you?): " + reply.(string)) } else { fmt.Println("failed to get a reply for (who are you?)") } }) }
func (bitverseObserver *BitverseObserver) OnConnected(node *bitverse.EdgeNode, remoteNode *bitverse.RemoteNode) { fmt.Println("-> now connected to super node " + remoteNode.Id()) prv, pub, err := bitverse.ImportPem("cert") if err != nil { fmt.Println(err) } node.ClaimOwnership(repoId, secret, prv, pub, 5, func(err error, repo interface{}) { if err != nil { fmt.Println("failed to claim repo: " + err.Error()) } else { fmt.Println("sucessfully claimed repo <test>") testRepo := repo.(*bitverse.RepoService) testRepo.Store("myKey", "myValue", 5, func(err error, oldValue interface{}) { if err != nil { fmt.Println("failed to store key in bitverse network: " + err.Error()) } else { switch oldValue.(type) { case string: fmt.Println("replacing key-value pair in the bitverse network, old value was " + oldValue.(string)) case nil: fmt.Println("storing new key-value pair in the bitverse network") } fmt.Println("retreiving key <myKey>") testRepo.Lookup("myKey", 5, func(err error, value interface{}) { if err != nil { fmt.Println("failed to get value from the bitverse network: " + err.Error()) } else { switch value.(type) { case string: fmt.Println("the value is " + value.(string)) case nil: fmt.Println("unknown key") } } }) } }) } }) }