Skip to content

Commit

Permalink
Changed to support 1-way connections
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Apr 19, 2020
1 parent eacdf54 commit 1092abe
Show file tree
Hide file tree
Showing 9 changed files with 470 additions and 462 deletions.
4 changes: 2 additions & 2 deletions api/admin/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

// Peerable can return a group of peers
type Peerable interface{ Peers() []utils.IPDesc }
type Peerable interface{ IPs() []utils.IPDesc }

// Networking provides helper methods for tracking the current network state
type Networking struct{ peers Peerable }

// Peers returns the current peers
func (n *Networking) Peers() ([]string, error) {
ipDescs := n.peers.Peers()
ipDescs := n.peers.IPs()
ips := make([]string, len(ipDescs))
for i, ipDesc := range ipDescs {
ips[i] = ipDesc.String()
Expand Down
288 changes: 0 additions & 288 deletions networking/addrset.go

This file was deleted.

3 changes: 2 additions & 1 deletion networking/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ type Builder struct{ Codec }
func (m Builder) GetVersion() (Msg, error) { return m.Pack(GetVersion, nil) }

// Version message
func (m Builder) Version(networkID uint32, myTime uint64, myVersion string) (Msg, error) {
func (m Builder) Version(networkID uint32, myTime uint64, ip utils.IPDesc, myVersion string) (Msg, error) {
return m.Pack(Version, map[Field]interface{}{
NetworkID: networkID,
MyTime: myTime,
IP: ip,
VersionStr: myVersion,
})
}
Expand Down
9 changes: 8 additions & 1 deletion networking/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
VersionStr Field = iota // Used in handshake
NetworkID // Used in handshake
MyTime // Used in handshake
IP // Used in handshake
Peers // Used in handshake
ChainID // Used for dispatching
RequestID // Used for all messages
Expand All @@ -38,6 +39,8 @@ func (f Field) Packer() func(*wrappers.Packer, interface{}) {
return wrappers.TryPackInt
case MyTime:
return wrappers.TryPackLong
case IP:
return wrappers.TryPackIP
case Peers:
return wrappers.TryPackIPList
case ChainID: // TODO: This will be shortened to use a modified varint spec
Expand Down Expand Up @@ -72,6 +75,8 @@ func (f Field) Unpacker() func(*wrappers.Packer) interface{} {
return wrappers.TryUnpackInt
case MyTime:
return wrappers.TryUnpackLong
case IP:
return wrappers.TryUnpackIP
case Peers:
return wrappers.TryUnpackIPList
case ChainID: // TODO: This will be shortened to use a modified varint spec
Expand Down Expand Up @@ -105,6 +110,8 @@ func (f Field) String() string {
return "NetworkID"
case MyTime:
return "MyTime"
case IP:
return "IP"
case Peers:
return "Peers"
case ChainID:
Expand Down Expand Up @@ -161,7 +168,7 @@ var (
Messages = map[salticidae.Opcode][]Field{
// Handshake:
GetVersion: []Field{},
Version: []Field{NetworkID, MyTime, VersionStr},
Version: []Field{NetworkID, MyTime, IP, VersionStr},
GetPeerList: []Field{},
PeerList: []Field{Peers},
// Bootstrapping:
Expand Down
Loading

0 comments on commit 1092abe

Please sign in to comment.