-
Notifications
You must be signed in to change notification settings - Fork 67
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
feat: peering implementation #260
Conversation
@alvin-reyes why not use the go-ipfs peering package at https://github.com/ipfs/go-ipfs/tree/master/peering |
handlers.go
Outdated
|
||
peerParamId, _ := peer.Decode(peerParam.ID) | ||
// add the peer(s) | ||
s.Node.Peering.AddPeer( |
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 not build/verify the multiaddr before adding it for peering? if it fails halfway, it means partial adding. Except this it your intention
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.
@en0ma Not sure what you mean. multiaddr.NewMultiaddr
parses and verifies the multiaddr. So we only add a peer if all their multiaddrs are correctly parsed
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 meant the complete peer sent for the request - if there are multiple peers, 1 fails and 1 pass - it adds 1, yet returns an error for the request. So my question is, is that intended?
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.
Yeah maybe we should add all of them together. If one fails we don't add anything
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.
if one of the address is invalid, then the entire request should be invalid. It would be best for us to impose an absolute correctness of the addresses and inform the consumer if one of them is invalid.
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.
@alvin-reyes on line 479, it is not all or nothing - which is what I am pointing at
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.
Yes. That's why we return a json response immediately if one of the addrs is invalid.
Line 466 - 475
for _, addr := range peerParam.Addrs {
a, err := multiaddr.NewMultiaddr(addr)
if err != nil {
log.Errorf("handlePeeringPeersAdd error: %s", err)
return c.JSON(http.StatusBadRequest,
util.PeeringPeerAddMessage{
"Adding Peer(s) on Peering failed, the addr is invalid" + addr, params})
}
multiAddrs = append(multiAddrs, a)
}
If one of them is invalid, the entire request to add will be cancelled with StatusBadRequest response. It'll also show the message and list of invalid addrs.
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 are looking at per addr level. I am talking about per peer level. If 2 peers are sent - if 1 is added and the other fails
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.
handlers.go
Outdated
|
||
peerParamId, _ := peer.Decode(peerParam.ID) | ||
// add the peer(s) | ||
s.Node.Peering.AddPeer( |
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.
@en0ma Not sure what you mean. multiaddr.NewMultiaddr
parses and verifies the multiaddr. So we only add a peer if all their multiaddrs are correctly parsed
handlers.go
Outdated
type PeeringPeerRemoveMessage struct { | ||
Message string `json: Message` | ||
PeersRemove []peer.ID `json: Peers` | ||
} |
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.
nit: put this on util/peering.go
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. I think this should be in a model package rather than util. We can revisit once we start refactoring
the codebase.
node/modules/peering/peering.go
Outdated
func (ps *EstuaryPeeringService) Stop() error { | ||
return ps.PeeringService.Stop() | ||
} | ||
|
||
func (ps *EstuaryPeeringService) ListPeers() []peer.AddrInfo { | ||
return ps.PeeringService.ListPeers() | ||
} | ||
|
||
func (ps *EstuaryPeeringService) AddPeer(info peer.AddrInfo) { | ||
ps.PeeringService.AddPeer(info) | ||
} | ||
|
||
func (ps *EstuaryPeeringService) RemovePeer(peerId peer.ID) { | ||
ps.PeeringService.RemovePeer(peerId) | ||
} |
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'm not sure why we need to wrap everything up under the name of EstuaryPeeringService
. Can't we simply use ps.PeeringService
altogether?
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 want to make sure that we are loosely couple from the implementation so that we can extend the functionality. I wrapped it so that can add more features and decorate
this later if needed.
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.
LGTM
Changes
Implemented Peering based on IPFS peering
Related Issue
#259
How to use
Add peering.peers via estuary cli
Add peering.peers via estuary-shuttle cli
Peering endpoints
Add peers
Remove
List
Start
Stop
Verification
Add peers
Remove peers
List all peers
Start peering
Stop peering