advertisment.go raw

   1  package p2padvt
   2  
   3  import (
   4  	"github.com/niubaoshu/gotiny"
   5  	
   6  	"github.com/p9c/p9/pkg/util"
   7  	"github.com/p9c/p9/pkg/util/routeable"
   8  )
   9  
  10  var Magic = []byte{'a', 'd', 'v', 1}
  11  
  12  // Advertisment is the contact details, UUID and services available on a node
  13  type Advertisment struct {
  14  	// IPs is here stored as an empty struct map so shuffling is automatic
  15  	IPs map[string]struct{}
  16  	// P2P is the port on which the node can be contacted by other peers
  17  	P2P uint16
  18  	// UUID is a unique identifier randomly generated at each initialisation
  19  	UUID uint64
  20  	// // Services reflects the services available, in time the controller will be
  21  	// // merged into wire, along with other key protocols implemented in pod
  22  	// Services wire.ServiceFlag
  23  }
  24  
  25  // Get returns an advertisment message
  26  func Get(uuid uint64, listeners string) []byte {
  27  	_, ips := routeable.GetAddressesAndInterfaces()
  28  	adv := &Advertisment{
  29  		IPs:  ips,
  30  		P2P:  util.GetActualPort(listeners),
  31  		UUID: uuid,
  32  		// Services: node.Services,
  33  	}
  34  	ad := gotiny.Marshal(&adv)
  35  	return ad
  36  }
  37