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
Migrate to KCP backend. #44
Conversation
… and a lot of error handling. Still not usable as of yet.
network/message.go
Outdated
return err | ||
} | ||
|
||
n, err := ctx.stream.Write(bytes) |
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 client or stream is ever nil, there will be panics here.
Also check if err == nil
first before n != len(bytes)
so the error returned is more appropriate.
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.
stream
and client
are guaranteed to be non-nil as that is the only way we would construct out MessageContext
's.
A few questions about this PR:
|
|
There is also a sticky packet problem where more than one packets ‘stick’ together on one Recv, since TCP and KCP are stream protocols. |
Mostly solved the issue of sticky packets by using buffered IO. |
…ore documentation.
…t modify parameters for `network.Listen()`.
@doug-perlin @abbychau Can you guys look into detecting when peers disconnect? From what I see using We need to know when peers are dead to remove them from the routing table of the node. I'll stop working on this PR for now since everything but disconnection and merging is done 😄. |
the disconnection can be a separate pr, this is already pretty big already |
I'd recommend sticking disconnection in the PR just in case so that it represents one huge transition to KCP. Partially leaving features out would be odd; |
|
||
// Check if unsigned varint overflows, or if protobuf message is too large. | ||
if n <= 0 || size > 1<<31-1 { | ||
return nil, errors.New("message len is either broken or too large") |
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.
let's print the size in the error:
return nil, fmt.Errorf("invalid message length: %d bytes", size)
func (n *Network) Listen() { | ||
listener, err := net.Listen("tcp", ":"+strconv.Itoa(n.Port)) | ||
listener, err := kcp.ListenWithOptions(":"+strconv.Itoa(int(n.Port)), nil, 10, 3) |
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.
Want to respect the host too:
kcp.ListenWithOptions(n.Address(), nil, 10, 3)
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.
Best not in case we have other clients wanting to connect through different specific server IP's.
if err != nil { | ||
glog.Error(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.
Don't need to glog here, it will get propagated up and may cause a double log.
… and a lot of error handling. Still not usable as of yet.
…ue of sticky sockets.
…ore documentation.
…t modify parameters for `network.Listen()`.
# Conflicts: # examples/clusters/messages/cluster.pb.go
Porting from gRPC to KCP.
TODO:
1. Strange bug that upon peer discovery, the node willDial()
itself. Look intonetwork/discovery/*.go
2. Have the bootstrapping of peers happen only after the server is ready to listen for peers. In other words, block until server is ready inmain.go
.3. Figure out how to determine whether or not a peer has properly disconnected exactly once* to remove from the Kademlia peer routing table.4. Rebase intomaster
and merge.