go-libp2p-kad-dht/Message.go

38 lines
1.0 KiB
Go
Raw Normal View History

package dht
2014-08-09 22:28:46 -07:00
import (
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
2014-08-09 22:28:46 -07:00
peer "github.com/jbenet/go-ipfs/peer"
)
2014-09-16 00:52:57 -07:00
func peerInfo(p *peer.Peer) *Message_Peer {
pbp := new(Message_Peer)
2014-08-19 19:14:52 -07:00
if len(p.Addresses) == 0 || p.Addresses[0] == nil {
pbp.Addr = proto.String("")
} else {
addr, err := p.Addresses[0].String()
if err != nil {
//Temp: what situations could cause this?
panic(err)
}
pbp.Addr = &addr
2014-08-09 22:28:46 -07:00
}
pid := string(p.ID)
pbp.Id = &pid
return pbp
}
2014-09-16 00:52:57 -07:00
// GetClusterLevel gets and adjusts the cluster level on the message.
// a +/- 1 adjustment is needed to distinguish a valid first level (1) and
// default "no value" protobuf behavior (0)
func (m *Message) GetClusterLevel() int32 {
return m.GetClusterLevelRaw() - 1
}
2014-09-16 00:52:57 -07:00
// SetClusterLevel adjusts and sets the cluster level on the message.
// a +/- 1 adjustment is needed to distinguish a valid first level (1) and
// default "no value" protobuf behavior (0)
func (m *Message) SetClusterLevel(level int32) {
m.ClusterLevelRaw = &level
}