mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 13:01:39 +00:00
Show proto in admin socket, link linkInfo from peer, other fixes
This commit is contained in:
parent
2b8648e2b3
commit
61774aed3b
@ -666,7 +666,8 @@ func (a *admin) getData_getPeers() []admin_nodeInfo {
|
||||
{"uptime", int(time.Since(p.firstSeen).Seconds())},
|
||||
{"bytes_sent", atomic.LoadUint64(&p.bytesSent)},
|
||||
{"bytes_recvd", atomic.LoadUint64(&p.bytesRecvd)},
|
||||
{"endpoint", p.endpoint},
|
||||
{"proto", p.intf.info.linkType},
|
||||
{"endpoint", p.intf.info.remote},
|
||||
{"box_pub_key", hex.EncodeToString(p.box[:])},
|
||||
}
|
||||
peerInfos = append(peerInfos, info)
|
||||
@ -692,7 +693,8 @@ func (a *admin) getData_getSwitchPeers() []admin_nodeInfo {
|
||||
{"port", elem.port},
|
||||
{"bytes_sent", atomic.LoadUint64(&peer.bytesSent)},
|
||||
{"bytes_recvd", atomic.LoadUint64(&peer.bytesRecvd)},
|
||||
{"endpoint", peer.endpoint},
|
||||
{"proto", peer.intf.info.linkType},
|
||||
{"endpoint", peer.intf.info.remote},
|
||||
{"box_pub_key", hex.EncodeToString(peer.box[:])},
|
||||
}
|
||||
peerInfos = append(peerInfos, info)
|
||||
|
@ -97,7 +97,15 @@ func (c *Core) DEBUG_getPeers() *peers {
|
||||
}
|
||||
|
||||
func (ps *peers) DEBUG_newPeer(box crypto.BoxPubKey, sig crypto.SigPubKey, link crypto.BoxSharedKey) *peer {
|
||||
return ps.newPeer(&box, &sig, &link, "(simulator)", nil)
|
||||
sim := linkInterface{
|
||||
name: "(simulator)",
|
||||
info: linkInfo{
|
||||
local: "(simulator)",
|
||||
remote: "(simulator)",
|
||||
linkType: "sim",
|
||||
},
|
||||
}
|
||||
return ps.newPeer(&box, &sig, &link, &sim, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -173,7 +173,7 @@ func (intf *linkInterface) handler() error {
|
||||
intf.link.mutex.Unlock()
|
||||
// Create peer
|
||||
shared := crypto.GetSharedKey(myLinkPriv, &meta.link)
|
||||
intf.peer = intf.link.core.peers.newPeer(&meta.box, &meta.sig, shared, intf.name, func() { intf.msgIO.close() })
|
||||
intf.peer = intf.link.core.peers.newPeer(&meta.box, &meta.sig, shared, intf, func() { intf.msgIO.close() })
|
||||
if intf.peer == nil {
|
||||
return errors.New("failed to create peer")
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ type peer struct {
|
||||
bytesRecvd uint64 // To track bandwidth usage for getPeers
|
||||
// BUG: sync/atomic, 32 bit platforms need the above to be the first element
|
||||
core *Core
|
||||
intf *linkInterface
|
||||
port switchPort
|
||||
box crypto.BoxPubKey
|
||||
sig crypto.SigPubKey
|
||||
@ -113,18 +114,19 @@ type peer struct {
|
||||
}
|
||||
|
||||
// Creates a new peer with the specified box, sig, and linkShared keys, using the lowest unoccupied port number.
|
||||
func (ps *peers) newPeer(box *crypto.BoxPubKey, sig *crypto.SigPubKey, linkShared *crypto.BoxSharedKey, endpoint string, closer func()) *peer {
|
||||
func (ps *peers) newPeer(box *crypto.BoxPubKey, sig *crypto.SigPubKey, linkShared *crypto.BoxSharedKey, intf *linkInterface, closer func()) *peer {
|
||||
now := time.Now()
|
||||
p := peer{box: *box,
|
||||
sig: *sig,
|
||||
shared: *crypto.GetSharedKey(&ps.core.boxPriv, box),
|
||||
linkShared: *linkShared,
|
||||
endpoint: endpoint,
|
||||
firstSeen: now,
|
||||
doSend: make(chan struct{}, 1),
|
||||
dinfo: make(chan *dhtInfo, 1),
|
||||
close: closer,
|
||||
core: ps.core}
|
||||
core: ps.core,
|
||||
intf: intf,
|
||||
}
|
||||
ps.mutex.Lock()
|
||||
defer ps.mutex.Unlock()
|
||||
oldPorts := ps.getPorts()
|
||||
|
@ -67,7 +67,15 @@ func (r *router) init(core *Core) {
|
||||
r.addr = *address.AddrForNodeID(&r.core.dht.nodeID)
|
||||
r.subnet = *address.SubnetForNodeID(&r.core.dht.nodeID)
|
||||
in := make(chan []byte, 1) // TODO something better than this...
|
||||
p := r.core.peers.newPeer(&r.core.boxPub, &r.core.sigPub, &crypto.BoxSharedKey{}, "(self)", nil)
|
||||
self := linkInterface{
|
||||
name: "(self)",
|
||||
info: linkInfo{
|
||||
local: "(self)",
|
||||
remote: "(self)",
|
||||
linkType: "self",
|
||||
},
|
||||
}
|
||||
p := r.core.peers.newPeer(&r.core.boxPub, &r.core.sigPub, &crypto.BoxSharedKey{}, &self, nil)
|
||||
p.out = func(packet []byte) { in <- packet }
|
||||
r.in = in
|
||||
out := make(chan []byte, 32)
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
||||
)
|
||||
|
||||
@ -39,16 +38,7 @@ type tcp struct {
|
||||
listeners map[string]net.Listener
|
||||
listenerstops map[string]chan bool
|
||||
calls map[string]struct{}
|
||||
conns map[tcpInfo](chan struct{})
|
||||
}
|
||||
|
||||
// This is used as the key to a map that tracks existing connections, to prevent multiple connections to the same keys and local/remote address pair from occuring.
|
||||
// Different address combinations are allowed, so multi-homing is still technically possible (but not necessarily advisable).
|
||||
type tcpInfo struct {
|
||||
box crypto.BoxPubKey
|
||||
sig crypto.SigPubKey
|
||||
localAddr string
|
||||
remoteAddr string
|
||||
conns map[linkInfo](chan struct{})
|
||||
}
|
||||
|
||||
// Wrapper function to set additional options for specific connection types.
|
||||
@ -90,7 +80,7 @@ func (t *tcp) init(l *link) error {
|
||||
t.reconfigure = make(chan chan error, 1)
|
||||
t.mutex.Lock()
|
||||
t.calls = make(map[string]struct{})
|
||||
t.conns = make(map[tcpInfo](chan struct{}))
|
||||
t.conns = make(map[linkInfo](chan struct{}))
|
||||
t.listeners = make(map[string]net.Listener)
|
||||
t.listenerstops = make(map[string]chan bool)
|
||||
t.mutex.Unlock()
|
||||
@ -167,20 +157,20 @@ func (t *tcp) listen(listenaddr string) error {
|
||||
// Runs the listener, which spawns off goroutines for incoming connections.
|
||||
func (t *tcp) listener(listenaddr string) {
|
||||
t.mutex.Lock()
|
||||
listener, ok := t.listeners[listenaddr]
|
||||
listener, ok1 := t.listeners[listenaddr]
|
||||
listenerstop, ok2 := t.listenerstops[listenaddr]
|
||||
t.mutex.Unlock()
|
||||
if !ok || !ok2 {
|
||||
if !ok1 || !ok2 {
|
||||
t.link.core.log.Errorln("Tried to start TCP listener for", listenaddr, "which doesn't exist")
|
||||
return
|
||||
}
|
||||
reallistenaddr := listener.Addr().String()
|
||||
defer listener.Close()
|
||||
t.link.core.log.Infoln("Listening for TCP on:", reallistenaddr)
|
||||
accepted := make(chan bool)
|
||||
for {
|
||||
var sock net.Conn
|
||||
var err error
|
||||
accepted := make(chan bool)
|
||||
go func() {
|
||||
sock, err = listener.Accept()
|
||||
accepted <- true
|
||||
@ -191,26 +181,14 @@ func (t *tcp) listener(listenaddr string) {
|
||||
t.link.core.log.Errorln("Failed to accept connection:", err)
|
||||
return
|
||||
}
|
||||
go t.handler(sock, true)
|
||||
case <-listenerstop:
|
||||
t.link.core.log.Errorln("Stopping TCP listener on:", reallistenaddr)
|
||||
return
|
||||
default:
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go t.handler(sock, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if we already have a connection to this node
|
||||
func (t *tcp) isAlreadyConnected(info tcpInfo) bool {
|
||||
t.mutex.Lock()
|
||||
defer t.mutex.Unlock()
|
||||
_, isIn := t.conns[info]
|
||||
return isIn
|
||||
}
|
||||
|
||||
// Checks if we already are calling this address
|
||||
func (t *tcp) isAlreadyCalling(saddr string) bool {
|
||||
t.mutex.Lock()
|
||||
|
Loading…
Reference in New Issue
Block a user