forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocator.go
49 lines (40 loc) · 1.06 KB
/
locator.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
48
49
package socketface
import (
"errors"
"github.com/gogf/greuse"
"github.com/usnistgov/ndn-dpdk/iface"
)
const (
schemeUnix = "unix"
schemeUDP = "udp"
schemeTCP = "tcp"
)
// Locator describes network and addresses of a socket.
type Locator struct {
*Config
Network string `json:"scheme"`
Local string `json:"local,omitempty"`
Remote string `json:"remote"`
}
// Scheme returns the protocol.
func (loc Locator) Scheme() string {
return loc.Network
}
// WithSchemeField implements iface.locatorWithSchemeField interface.
func (Locator) WithSchemeField() {}
// Validate checks the addresses.
func (loc Locator) Validate() error {
_, eR := greuse.ResolveAddr(loc.Network, loc.Remote)
var eL error
if loc.Local != "" && !(loc.Network == schemeUnix && loc.Local == "@") {
_, eL = greuse.ResolveAddr(loc.Network, loc.Local)
}
return errors.Join(eR, eL)
}
// CreateFace creates a face from this Locator.
func (loc Locator) CreateFace() (iface.Face, error) {
return New(loc)
}
func init() {
iface.RegisterLocatorScheme[Locator](schemeUnix, schemeUDP, schemeTCP)
}