whisper: update the peercount

The new peer was timing out because the peer list wasn't
updated.
This commit is contained in:
Guillaume Ballet 2018-03-27 18:52:08 +02:00
parent 5e5ae75be5
commit 80d093ddd4
2 changed files with 6 additions and 11 deletions

View file

@ -226,7 +226,7 @@ func initialize() {
if err != nil { if err != nil {
utils.Fatalf("Error parsing the bootnode addr: %v", err) utils.Fatalf("Error parsing the bootnode addr: %v", err)
} }
fmt.Println(libp2pbootaddr) fmt.Println("bootstrap addr: ", libp2pbootaddr)
libp2pPeers = append(libp2pPeers, libp2pbootaddr) libp2pPeers = append(libp2pPeers, libp2pbootaddr)
} else { } else {
if len(*argEnode) == 0 { if len(*argEnode) == 0 {

View file

@ -172,7 +172,7 @@ func (server *LibP2PWhisperServer) connectToPeer(p *LibP2PPeer) error {
// Create a stream with the peer // Create a stream with the peer
s, err := server.Host.NewStream(context.Background(), p.id, WhisperProtocolString) s, err := server.Host.NewStream(context.Background(), p.id, WhisperProtocolString)
if err != nil { if err != nil {
panic(err) return err
} }
// Save the stream // Save the stream
@ -181,15 +181,10 @@ func (server *LibP2PWhisperServer) connectToPeer(p *LibP2PPeer) error {
} }
p.connectionStream = &lps p.connectionStream = &lps
// Send a first message to notify the remote peer we want // If we got here, it means that a connection was established.
// to connect // Save the peer.
connectMsg := p2p.Msg{
Code: lp2pPeerCode,
Size: 0,
Payload: bytes.NewReader([]byte{0}),
}
err = lps.WriteMsg(connectMsg) // TODO send my known list of peers
return err return err
} }
@ -245,7 +240,7 @@ func (server *LibP2PWhisperServer) Stop() {
// PeerCount returns the peer count for the node // PeerCount returns the peer count for the node
func (server *LibP2PWhisperServer) PeerCount() int { func (server *LibP2PWhisperServer) PeerCount() int {
return 0 return len(server.Peers)
} }
// Enode returns the enode address of the node // Enode returns the enode address of the node