introduce PeerUID type
This commit is contained in:
1 parent
ace56da7b3
commit
c7dd48d769
4 files changed
+14
-6
No files matched your search
+1
-1
@@ -78,7 +78,7 @@ func (conn *LocalConnection) handshake(enc *gob.Encoder, dec *gob.Decoder, accep
|
|||||||
if existingConn, found := conn.Router.Ourself.ConnectionTo(name); found && existingConn.Established() {
|
if existingConn, found := conn.Router.Ourself.ConnectionTo(name); found && existingConn.Established() {
|
||||||
return fmt.Errorf("Already have connection to %s at %s", existingConn.Remote(), existingConn.RemoteTCPAddr())
|
return fmt.Errorf("Already have connection to %s at %s", existingConn.Remote(), existingConn.RemoteTCPAddr())
|
||||||
}
|
}
|
||||||
uid, err := strconv.ParseUint(uidStr, 10, 64)
|
uid, err := ParsePeerUID(uidStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ func (peers *Peers) MarshalJSON() ([]byte, error) {
|
|||||||
type p struct {
|
type p struct {
|
||||||
Name string
|
Name string
|
||||||
NickName string
|
NickName string
|
||||||
UID uint64
|
UID PeerUID
|
||||||
Version uint64
|
Version uint64
|
||||||
Connections []Connection
|
Connections []Connection
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-3
@@ -3,13 +3,21 @@ package router
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PeerUID uint64
|
||||||
|
|
||||||
|
func ParsePeerUID(s string) (PeerUID, error) {
|
||||||
|
uid, err := strconv.ParseUint(s, 10, 64)
|
||||||
|
return PeerUID(uid), err
|
||||||
|
}
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
Name PeerName
|
Name PeerName
|
||||||
NameByte []byte
|
NameByte []byte
|
||||||
NickName string
|
NickName string
|
||||||
UID uint64
|
UID PeerUID
|
||||||
version uint64
|
version uint64
|
||||||
localRefCount uint64 // maintained by Peers
|
localRefCount uint64 // maintained by Peers
|
||||||
connections map[PeerName]Connection
|
connections map[PeerName]Connection
|
||||||
@@ -17,9 +25,9 @@ type Peer struct {
|
|||||||
|
|
||||||
type ConnectionSet map[Connection]struct{}
|
type ConnectionSet map[Connection]struct{}
|
||||||
|
|
||||||
func NewPeer(name PeerName, nickName string, uid uint64, version uint64) *Peer {
|
func NewPeer(name PeerName, nickName string, uid PeerUID, version uint64) *Peer {
|
||||||
if uid == 0 {
|
if uid == 0 {
|
||||||
uid = randUint64()
|
uid = PeerUID(randUint64())
|
||||||
}
|
}
|
||||||
return &Peer{
|
return &Peer{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ type PeerNameSet map[PeerName]struct{}
|
|||||||
type PeerSummary struct {
|
type PeerSummary struct {
|
||||||
NameByte []byte
|
NameByte []byte
|
||||||
NickName string
|
NickName string
|
||||||
UID uint64
|
UID PeerUID
|
||||||
Version uint64
|
Version uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user