introduce PeerUID type

This commit is contained in:
Matthias Radestock committed 2015-05-14 12:35:01 +01:00
1 parent ace56da7b3
commit c7dd48d769
4 files changed
+14 -6

No files matched your search

+1 -1
View File
@@ -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() {
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 {
return err
}
+1 -1
View File
@@ -38,7 +38,7 @@ func (peers *Peers) MarshalJSON() ([]byte, error) {
type p struct {
Name string
NickName string
UID uint64
UID PeerUID
Version uint64
Connections []Connection
}
+11 -3
View File
@@ -3,13 +3,21 @@ package router
import (
"fmt"
"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 {
Name PeerName
NameByte []byte
NickName string
UID uint64
UID PeerUID
version uint64
localRefCount uint64 // maintained by Peers
connections map[PeerName]Connection
@@ -17,9 +25,9 @@ type Peer 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 {
uid = randUint64()
uid = PeerUID(randUint64())
}
return &Peer{
Name: name,
+1 -1
View File
@@ -28,7 +28,7 @@ type PeerNameSet map[PeerName]struct{}
type PeerSummary struct {
NameByte []byte
NickName string
UID uint64
UID PeerUID
Version uint64
}