-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
refac(net, exchange, dht) network service errors #101
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,23 +103,26 @@ func (dht *IpfsDHT) Connect(ctx context.Context, npeer *peer.Peer) (*peer.Peer, | |
} | ||
|
||
// HandleMessage implements the inet.Handler interface. | ||
func (dht *IpfsDHT) HandleMessage(ctx context.Context, mes msg.NetMessage) (msg.NetMessage, error) { | ||
func (dht *IpfsDHT) HandleMessage(ctx context.Context, mes msg.NetMessage) msg.NetMessage { | ||
|
||
mData := mes.Data() | ||
if mData == nil { | ||
return nil, errors.New("message did not include Data") | ||
// TODO handle/log err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prob should keep the old error text here commented to know what to modify it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going through and adding logging now. |
||
return nil | ||
} | ||
|
||
mPeer := mes.Peer() | ||
if mPeer == nil { | ||
return nil, errors.New("message did not include a Peer") | ||
// TODO handle/log err | ||
return nil | ||
} | ||
|
||
// deserialize msg | ||
pmes := new(Message) | ||
err := proto.Unmarshal(mData, pmes) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to decode protobuf message: %v\n", err) | ||
// TODO handle/log err | ||
return nil | ||
} | ||
|
||
// update the peer (on valid msgs only) | ||
|
@@ -133,27 +136,30 @@ func (dht *IpfsDHT) HandleMessage(ctx context.Context, mes msg.NetMessage) (msg. | |
// get handler for this msg type. | ||
handler := dht.handlerForMsgType(pmes.GetType()) | ||
if handler == nil { | ||
return nil, errors.New("Recieved invalid message type") | ||
// TODO handle/log err | ||
return nil | ||
} | ||
|
||
// dispatch handler. | ||
rpmes, err := handler(mPeer, pmes) | ||
if err != nil { | ||
return nil, err | ||
// TODO handle/log err | ||
return nil | ||
} | ||
|
||
// if nil response, return it before serializing | ||
if rpmes == nil { | ||
return nil, nil | ||
return nil | ||
} | ||
|
||
// serialize response msg | ||
rmes, err := msg.FromObject(mPeer, rpmes) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to encode protobuf message: %v\n", err) | ||
// TODO handle/log err | ||
return nil | ||
} | ||
|
||
return rmes, nil | ||
return rmes | ||
} | ||
|
||
// sendRequest sends out a request using dht.sender, but also makes sure to | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
curious: why couldnt the same error propagation work, and then have
Service
be the only one to send it over to through a 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.
e.g.
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.
These changes are based on this discussion:
#69 (comment)
It's that it's weird to send errors back down to the service. What does it mean to return error in a handler function? What is the service meant to do with this error?
It would appear that the better thing to do is for the handler to log and perform error handling internally.