forked from libp2p/go-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto.go
39 lines (32 loc) · 1011 Bytes
/
proto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package autonat
import (
"github.com/libp2p/go-libp2p/core/peer"
pb "github.com/libp2p/go-libp2p/p2p/host/autonat/pb"
ma "github.com/multiformats/go-multiaddr"
)
// AutoNATProto identifies the autonat service protocol
const AutoNATProto = "/libp2p/autonat/1.0.0"
func newDialMessage(pi peer.AddrInfo) *pb.Message {
msg := new(pb.Message)
msg.Type = pb.Message_DIAL.Enum()
msg.Dial = new(pb.Message_Dial)
msg.Dial.Peer = new(pb.Message_PeerInfo)
msg.Dial.Peer.Id = []byte(pi.ID)
msg.Dial.Peer.Addrs = make([][]byte, len(pi.Addrs))
for i, addr := range pi.Addrs {
msg.Dial.Peer.Addrs[i] = addr.Bytes()
}
return msg
}
func newDialResponseOK(addr ma.Multiaddr) *pb.Message_DialResponse {
dr := new(pb.Message_DialResponse)
dr.Status = pb.Message_OK.Enum()
dr.Addr = addr.Bytes()
return dr
}
func newDialResponseError(status pb.Message_ResponseStatus, text string) *pb.Message_DialResponse {
dr := new(pb.Message_DialResponse)
dr.Status = status.Enum()
dr.StatusText = &text
return dr
}