-
Notifications
You must be signed in to change notification settings - Fork 1
/
advertisment.go
36 lines (31 loc) · 1.01 KB
/
advertisment.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
package p2padvt
import (
"github.com/cybriq/gotiny"
"github.com/cybriq/p9/pkg/util"
"github.com/cybriq/p9/pkg/util/routeable"
)
var Magic = []byte{'a', 'd', 'v', 1}
// Advertisment is the contact details, UUID and services available on a node
type Advertisment struct {
// IPs is here stored as an empty struct map so shuffling is automatic
IPs map[string]struct{}
// P2P is the port on which the node can be contacted by other peers
P2P uint16
// UUID is a unique identifier randomly generated at each initialisation
UUID uint64
// // Services reflects the services available, in time the controller will be
// // merged into wire, along with other key protocols implemented in pod
// Services wire.ServiceFlag
}
// Get returns an advertisment message
func Get(uuid uint64, listeners string) []byte {
_, ips := routeable.GetAddressesAndInterfaces()
adv := &Advertisment{
IPs: ips,
P2P: util.GetActualPort(listeners),
UUID: uuid,
// Services: node.Services,
}
ad := gotiny.Marshal(&adv)
return ad
}