mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Improve API for GetAddress and GetSubnet
This commit is contained in:
parent
b5057d60ad
commit
c5782ca00a
5 changed files with 21 additions and 23 deletions
|
@ -425,13 +425,10 @@ func (a *admin) startTunWithMTU(ifname string, iftapmode bool, ifmtu int) error
|
||||||
|
|
||||||
func (a *admin) getData_getSelf() *admin_nodeInfo {
|
func (a *admin) getData_getSelf() *admin_nodeInfo {
|
||||||
table := a.core.switchTable.table.Load().(lookupTable)
|
table := a.core.switchTable.table.Load().(lookupTable)
|
||||||
addr := (*a.core.GetAddress())[:]
|
|
||||||
subnet := (*a.core.GetSubnet())[:]
|
|
||||||
subnet = append(subnet, 0, 0, 0, 0, 0, 0, 0, 0)
|
|
||||||
coords := table.self.getCoords()
|
coords := table.self.getCoords()
|
||||||
self := admin_nodeInfo{
|
self := admin_nodeInfo{
|
||||||
{"ip", net.IP(addr[:]).String()},
|
{"ip", a.core.GetAddress().String()},
|
||||||
{"subnet", fmt.Sprintf("%s/64", net.IP(subnet[:]).String())},
|
{"subnet", a.core.GetSubnet().String()},
|
||||||
{"coords", fmt.Sprint(coords)},
|
{"coords", fmt.Sprint(coords)},
|
||||||
}
|
}
|
||||||
return &self
|
return &self
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (c *Core) init(bpub *boxPubKey,
|
||||||
// This is pretty much required to completely avoid race conditions
|
// This is pretty much required to completely avoid race conditions
|
||||||
util_initByteStore()
|
util_initByteStore()
|
||||||
if c.log == nil {
|
if c.log == nil {
|
||||||
c.log = log.New(ioutil.Discard, "", 0)
|
c.log = log.New(ioutil.Discard, "", 0)
|
||||||
}
|
}
|
||||||
c.boxPub, c.boxPriv = *bpub, *bpriv
|
c.boxPub, c.boxPriv = *bpub, *bpriv
|
||||||
c.sigPub, c.sigPriv = *spub, *spriv
|
c.sigPub, c.sigPriv = *spub, *spriv
|
||||||
|
@ -156,13 +156,16 @@ func (c *Core) GetTreeID() *TreeID {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the IPv6 address of the Yggdrasil node. This is always a /128.
|
// Gets the IPv6 address of the Yggdrasil node. This is always a /128.
|
||||||
func (c *Core) GetAddress() *address {
|
func (c *Core) GetAddress() *net.IP {
|
||||||
return address_addrForNodeID(c.GetNodeID())
|
address := net.IP(address_addrForNodeID(c.GetNodeID())[:])
|
||||||
|
return &address
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the routed IPv6 subnet of the Yggdrasil node. This is always a /64.
|
// Gets the routed IPv6 subnet of the Yggdrasil node. This is always a /64.
|
||||||
func (c *Core) GetSubnet() *subnet {
|
func (c *Core) GetSubnet() *net.IPNet {
|
||||||
return address_subnetForNodeID(c.GetNodeID())
|
subnet := address_subnetForNodeID(c.GetNodeID())[:]
|
||||||
|
subnet = append(subnet, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||||
|
return &net.IPNet{ IP: subnet, Mask: net.CIDRMask(64, 128) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the output logger of the Yggdrasil node after startup. This may be
|
// Sets the output logger of the Yggdrasil node after startup. This may be
|
||||||
|
|
|
@ -16,10 +16,10 @@ type multicast struct {
|
||||||
func (m *multicast) init(core *Core) {
|
func (m *multicast) init(core *Core) {
|
||||||
m.core = core
|
m.core = core
|
||||||
m.groupAddr = "[ff02::114]:9001"
|
m.groupAddr = "[ff02::114]:9001"
|
||||||
// Check if we've been given any expressions
|
// Check if we've been given any expressions
|
||||||
if len(m.core.ifceExpr) == 0 {
|
if len(m.core.ifceExpr) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Ask the system for network interfaces
|
// Ask the system for network interfaces
|
||||||
allifaces, err := net.Interfaces()
|
allifaces, err := net.Interfaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -72,7 +72,7 @@ func (m *multicast) start() error {
|
||||||
go m.listen()
|
go m.listen()
|
||||||
go m.announce()
|
go m.announce()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *multicast) announce() {
|
func (m *multicast) announce() {
|
||||||
|
|
|
@ -302,14 +302,14 @@ func (iface *tcpInterface) reader(sock net.Conn, in func([]byte)) {
|
||||||
sock.SetReadDeadline(timeout)
|
sock.SetReadDeadline(timeout)
|
||||||
n, err := sock.Read(bs[len(frag):])
|
n, err := sock.Read(bs[len(frag):])
|
||||||
if err != nil || n == 0 {
|
if err != nil || n == 0 {
|
||||||
// iface.core.log.Println(err)
|
// iface.core.log.Println(err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
frag = bs[:len(frag)+n]
|
frag = bs[:len(frag)+n]
|
||||||
for {
|
for {
|
||||||
msg, ok, err := tcp_chop_msg(&frag)
|
msg, ok, err := tcp_chop_msg(&frag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// iface.core.log.Println(err)
|
// iface.core.log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
10
yggdrasil.go
10
yggdrasil.go
|
@ -4,7 +4,6 @@ import "encoding/hex"
|
||||||
import "flag"
|
import "flag"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "io/ioutil"
|
import "io/ioutil"
|
||||||
import "net"
|
|
||||||
import "os"
|
import "os"
|
||||||
import "os/signal"
|
import "os/signal"
|
||||||
import "syscall"
|
import "syscall"
|
||||||
|
@ -238,11 +237,10 @@ func main() {
|
||||||
}()
|
}()
|
||||||
// Make some nice output that tells us what our IPv6 address and subnet are.
|
// Make some nice output that tells us what our IPv6 address and subnet are.
|
||||||
// This is just logged to stdout for the user.
|
// This is just logged to stdout for the user.
|
||||||
address := (*n.core.GetAddress())[:]
|
address := n.core.GetAddress()
|
||||||
subnet := (*n.core.GetSubnet())[:]
|
subnet := n.core.GetSubnet()
|
||||||
subnet = append(subnet, 0, 0, 0, 0, 0, 0, 0, 0)
|
logger.Printf("Your IPv6 address is %s", address.String())
|
||||||
logger.Printf("Your IPv6 address is %s", net.IP(address).String())
|
logger.Printf("Your IPv6 subnet is %s", subnet.String())
|
||||||
logger.Printf("Your IPv6 subnet is %s/64", net.IP(subnet).String())
|
|
||||||
// Catch interrupts from the operating system to exit gracefully.
|
// Catch interrupts from the operating system to exit gracefully.
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue