-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p gossip #211
p2p gossip #211
Conversation
@@ -186,11 +186,18 @@ func (app *SpacemeshApp) startSpacemesh(cmd *cobra.Command, args []string) { | |||
// start p2p services | |||
log.Info("Initializing P2P services") | |||
swarm, err := p2p.New(app.Config.P2P) | |||
if err != nil { | |||
log.Error("Error starting p2p services, err: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have different error prints than the one below, otherwise it will be hard to know what really failed
@@ -64,6 +71,7 @@ BOOTLOOP: | |||
case <-timeout.C: | |||
return ErrFailedToBoot | |||
case err := <-reschan: | |||
i++ | |||
if err == nil { | |||
return ErrFoundOurself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it implicit? Why not return ErrFoundOurself instead of nil (over the channel)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because this isn't really an error from this side. we tried to lookup a node, and we found it. hence error is nil.
this is an error only in the bootstrap context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as we talked offline - it is a valid case that a Lookup call on the local id will return the local node, it can happen if the local node is trying to bootstrap for the second time (in the case where it got killed after the first lookup). It is also possible to get itself in the first time the bootstrap is running. Anyways, in the case where the lookup outputs the local node we should continue with the bootstrap process and not fail it.
break BOOTLOOP | ||
} | ||
d.local.Warning("%d lookup didn't bootstrap the routing table", i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge the two log prints
time.Sleep(LookupIntervals) | ||
} | ||
} | ||
return nil // succeed | ||
} | ||
|
||
func (d *KadDHT) healthLoop() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used - remove
} | ||
} | ||
|
||
func (d *KadDHT) refresh() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used - remove
@@ -37,6 +39,12 @@ func (pm protocolMessage) Data() []byte { | |||
} | |||
|
|||
type swarm struct { | |||
started uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add comments to all of the members below - hard to understand their purpose just from their names
|
||
peer, err := s.dht.Lookup(peerPubKey) // blocking, might issue a network lookup that'll take time. | ||
peer, conn = s.gossip.Peer(peerPubKey) // check if he's a neighbor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this shouldn't concern swarm
// ErrBadFormat1 could'nt deserialize the payload | ||
ErrBadFormat1 = errors.New("bad msg format, could'nt deserialize 1") | ||
// ErrBadFormat2 could'nt deserialize the protocol message payload | ||
ErrBadFormat2 = errors.New("bad msg format, could'nt deserialize 2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need two errors that look the same?
func PrepareMessage(ns net.NetworkSession, data []byte) ([]byte, error) { | ||
encPayload, err := ns.Encrypt(data) | ||
if err != nil { | ||
return nil, fmt.Errorf("aborting send - failed to encrypt payload: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this log print is no longer relevant, change it
|
||
final, err := proto.Marshal(cmd) | ||
if err != nil { | ||
e := fmt.Errorf("aborting send - invalid msg format %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this log print is no longer relevant, change it
p2p/gossip/protocol.go
Outdated
func (s *Neighborhood) Broadcast(msg []byte) error { | ||
|
||
if len(s.peers) == 0 { | ||
panic("WHOHO") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use an error instead
Finally this PR is ready to merge, the comments mentioned here and some more are going to be implemented soon in a another PR. |
No description provided.