-
Notifications
You must be signed in to change notification settings - Fork 10
/
addr.go
47 lines (38 loc) · 800 Bytes
/
addr.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
40
41
42
43
44
45
46
47
package inproc
import (
"net"
"strings"
"github.com/aperturerobotics/bifrost/peer"
"github.com/pkg/errors"
)
var scheme = "inproc://"
type Addr struct {
peerID peer.ID
str string
}
// NewAddr builds a new Addr
func NewAddr(peerID peer.ID) *Addr {
return &Addr{
peerID: peerID,
str: scheme + peerID.String(),
}
}
// ParseAddr parses an address.
func ParseAddr(addr string) (net.Addr, error) {
if !strings.HasPrefix(addr, scheme) {
return nil, errors.Errorf("expected inproc prefix: %s", addr)
}
pid, err := peer.IDB58Decode(addr[len(scheme):])
if err != nil {
return nil, err
}
return NewAddr(pid), nil
}
func (a *Addr) Network() string {
return "inproc"
}
func (a *Addr) String() string {
return a.str
}
// _ is a type assertion
var _ net.Addr = ((*Addr)(nil))