-
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
Gossip protocol validation #496
Conversation
…node.Node as sender
log/log.go
Outdated
@@ -19,7 +19,7 @@ type Log struct { | |||
|
|||
// smlogger is the local app singleton logger. | |||
var AppLog Log | |||
var debugMode = false | |||
var debugMode = true |
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.
change back to false
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.
fixed
p2p/gossip/protocol.go
Outdated
prot.oldMessageMu.RLock() | ||
res, ok := prot.invalidMessageQ[h] | ||
prot.oldMessageMu.RUnlock() | ||
if ok { |
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 looks better :
if ok { | |
if !ok { | |
return Unknown | |
} | |
if !res { | |
return Invalid | |
} | |
return Valid |
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.
I agree, done
hare/messagevalidation.go
Outdated
return true | ||
} | ||
|
||
|
||
func (validator *MessageValidator) ValidateMessage(m *pb.HareMessage, k uint32) bool { |
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.
used only in tests. maybe not needed anymore ?
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.
True - adjusted the test and removed the method
Unknown | ||
) | ||
|
||
func (prot *Protocol) isMessageValid(h hash) Validity { |
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.
IsMessageValid
feels like it returns a bool, consider better naming
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.
Don't agree
close(c) | ||
} | ||
delete(sn.sim.protocolHandler, sn.Node.PublicKey().String()) | ||
delete(sn.sim.protocolDirectHandler, sn.Node.PublicKey().String()) |
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.
should be doing the same for protocolGossipHandler now..
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.
done
p2p/swarm.go
Outdated
|
||
func (pm gossipProtocolMessage) ReportValidation(protocol string, isValid bool) { | ||
if pm.validationChan != nil { | ||
pm.validationChan <- *service.NewMessageValidation(pm.Bytes(), protocol, isValid) |
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 de reference?
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.
fixed (see comment below)
p2p/service/service.go
Outdated
} | ||
|
||
func NewMessageValidation(msg []byte, prot string, isValid bool) *MessageValidation { | ||
return &MessageValidation{msg, prot, isValid} |
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 dereference that everywhere, why don't just return it by value ?
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.
true, changed it to return a value
p2p/swarm.go
Outdated
|
||
// RegisterGossipProtocol registers an handler for gossip based `protocol` | ||
func (s *swarm) RegisterGossipProtocol(protocol string) chan service.GossipMessage { | ||
mchan := make(chan service.GossipMessage, config.ConfigValues.BufferSize) |
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.
I know it was there already but it's better to take BufferSize from s.config.BufferSize
. (where its loaded from config/flags)
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.
fixed
hare/algorithm.go
Outdated
// TODO: should return error from message validation to indicate what failed, should retry only for contextual failure | ||
log.Warning("Message is not valid for either round") | ||
log.Warning("DirectMessage is not valid for either round") |
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.
DirectMessage? I believe it happened during refactoring.
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.
I believe you believe correctly
hare/broker.go
Outdated
} | ||
|
||
func (msg Message) reportValidationResult(isValid bool) { | ||
msg.validationChan <- *service.NewMessageValidation(msg.bytes, ProtoName, isValid) |
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.
Pass a pointer to the channel and don't deref.
To my understanding, it has no perf implications in this context. We can further discuss it if you like.
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.
msg.validationChan can be nil. nil will block.
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.
fixed
hare/messagevalidation.go
Outdated
return true | ||
} | ||
|
||
|
||
func (validator *MessageValidator) ValidateMessage(m *pb.HareMessage, k uint32) bool { |
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.
Remove. ValidateMessage is only used in the unit tests.
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.
removed
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.
I reviewed the hare code and approve it.
Ask the last reviewer to also approve the PR.
No description provided.