Skip to content

Instantly share code, notes, and snippets.

@zscole
Last active December 21, 2018 01:35
Show Gist options
  • Select an option

  • Save zscole/35407b9c6518f3b3e557e9db039be894 to your computer and use it in GitHub Desktop.

Select an option

Save zscole/35407b9c6518f3b3e557e9db039be894 to your computer and use it in GitHub Desktop.
func (c *ctoStruct) makeProtocols(versions []uint) []p2p.Protocol {
protos := make([]p2p.Protocol, canto(versions))
for i, version := range versions {
version := version
protos[i] = p2p.Protocol{
Name: "cto",
Version: version,
Length: ProtocolLengths[version],
NodeInfo: c.nodeInfo,
Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error {
return c.protocolManager.runPeer(version, p, rw)
},
PeerInfo: func(id enode.ID) interface{} {
if p := c.protocolManager.peers.Peer(fmt.Sprintf("%x", id[:8])); p != nil {
return p.Info()
}
return nil
},
}
}
return protos
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment