Skip to content
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

Merged
merged 8 commits into from Feb 2, 2019
Merged

Gossip protocol validation #496

merged 8 commits into from Feb 2, 2019

Conversation

zalmen
Copy link
Contributor

@zalmen zalmen commented Jan 30, 2019

No description provided.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change back to false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

prot.oldMessageMu.RLock()
res, ok := prot.invalidMessageQ[h]
prot.oldMessageMu.RUnlock()
if ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this looks better :

Suggested change
if ok {
if !ok {
return Unknown
}
if !res {
return Invalid
}
return Valid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, done

return true
}


func (validator *MessageValidator) ValidateMessage(m *pb.HareMessage, k uint32) bool {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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())
Copy link
Contributor

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..

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why de reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed (see comment below)

}

func NewMessageValidation(msg []byte, prot string, isValid bool) *MessageValidation {
return &MessageValidation{msg, prot, isValid}
Copy link
Contributor

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 ?

Copy link
Contributor Author

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)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

hare/algorithm.go Show resolved Hide resolved
hare/algorithm.go Show resolved Hide resolved
hare/algorithm.go Show resolved Hide resolved
// 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")
Copy link
Contributor

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.

Copy link
Contributor Author

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/algorithm.go Show resolved Hide resolved
hare/algorithm.go Show resolved Hide resolved
hare/broker.go Outdated
}

func (msg Message) reportValidationResult(isValid bool) {
msg.validationChan <- *service.NewMessageValidation(msg.bytes, ProtoName, isValid)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return true
}


func (validator *MessageValidator) ValidateMessage(m *pb.HareMessage, k uint32) bool {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

hare/messagevalidation.go Show resolved Hide resolved
@zalmen
Copy link
Contributor Author

zalmen commented Feb 1, 2019

@y0sher @gavraz done addressing your comments

Copy link
Contributor

@gavraz gavraz left a 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.

@zalmen zalmen merged commit 6dc06a8 into develop Feb 2, 2019
@zalmen zalmen deleted the gossip-protocol-validation branch February 3, 2019 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants