Skip to content

Commit

Permalink
node: only print that you are connected to a provider when its your f…
Browse files Browse the repository at this point in the history
…irst time, and print that the provider was re-probed otherwise
  • Loading branch information
lithdew committed Jun 17, 2020
1 parent c04607d commit f10b026
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (n *Node) Bootstrap() {
return
}

_, err = n.probe(conn)
err = n.probe(conn)
if err != nil {
return
}
Expand Down Expand Up @@ -531,21 +531,21 @@ func (n *Node) getClient(addr string) *monte.Client {
return client
}

func (n *Node) probe(conn *monte.Conn) (*Provider, error) {
provider, _ := n.providers.register(conn, nil, nil, true)
func (n *Node) probe(conn *monte.Conn) error {
provider, exists := n.providers.register(conn, nil, nil, true)

req := n.createHandshakePacket(nil).AppendTo([]byte{OpcodeHandshake})
res, err := conn.Request(req[:0], req)
if err != nil {
return provider, err
return err
}
packet, err := UnmarshalHandshakePacket(res)
if err != nil {
return provider, err
return err
}
err = packet.Validate(req[:0])
if err != nil {
return provider, err
return err
}

if packet.ID != nil {
Expand All @@ -556,14 +556,19 @@ func (n *Node) probe(conn *monte.Conn) (*Provider, error) {

// update the provider with id and services info
provider, _ = n.providers.register(conn, packet.ID, packet.Services, true)
if !exists {
log.Printf("You are now connected to %s. Services: %s", provider.Addr(), provider.Services())
} else {
log.Printf("Re-probed %s. Services: %s", provider.Addr(), provider.Services())
}

// update the routing table
n.tableLock.Lock()
n.table.Update(*packet.ID)
n.tableLock.Unlock()
}

return provider, nil
return nil
}

func (n *Node) Probe(addr string) error {
Expand All @@ -577,13 +582,11 @@ func (n *Node) Probe(addr string) error {
return err
}

provider, err := n.probe(conn)
err = n.probe(conn)
if err != nil {
return err
}

log.Printf("You are now connected to %s. Services: %s", provider.Addr(), provider.Services())

return nil
}

Expand Down

0 comments on commit f10b026

Please sign in to comment.