mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Link refactor (#941)
* Link refactoring * More refactoring * More tweaking * Cleaner shutdowns, UNIX socket support, more tweaks * Actorise links, remove mutex * SOCKS support
This commit is contained in:
parent
414aaf6eb9
commit
5ef61faeff
18 changed files with 738 additions and 698 deletions
|
@ -2,6 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
|
@ -15,6 +16,7 @@ import (
|
|||
//"sort"
|
||||
//"time"
|
||||
|
||||
"github.com/Arceliar/phony"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
||||
//"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
||||
|
@ -68,11 +70,11 @@ func (c *Core) GetSelf() SelfInfo {
|
|||
func (c *Core) GetPeers() []PeerInfo {
|
||||
var peers []PeerInfo
|
||||
names := make(map[net.Conn]string)
|
||||
c.links.mutex.Lock()
|
||||
for _, info := range c.links.links {
|
||||
names[info.conn] = info.lname
|
||||
}
|
||||
c.links.mutex.Unlock()
|
||||
phony.Block(&c.links, func() {
|
||||
for _, info := range c.links._links {
|
||||
names[info.conn] = info.lname
|
||||
}
|
||||
})
|
||||
ps := c.PacketConn.PacketConn.Debug.GetPeers()
|
||||
for _, p := range ps {
|
||||
var info PeerInfo
|
||||
|
@ -136,8 +138,17 @@ func (c *Core) GetSessions() []SessionInfo {
|
|||
// Listen starts a new listener (either TCP or TLS). The input should be a url.URL
|
||||
// parsed from a string of the form e.g. "tcp://a.b.c.d:e". In the case of a
|
||||
// link-local address, the interface should be provided as the second argument.
|
||||
func (c *Core) Listen(u *url.URL, sintf string) (*TcpListener, error) {
|
||||
return c.links.tcp.listenURL(u, sintf)
|
||||
func (c *Core) Listen(u *url.URL, sintf string) (*Listener, error) {
|
||||
switch u.Scheme {
|
||||
case "tcp":
|
||||
return c.links.tcp.listen(u, sintf)
|
||||
case "tls":
|
||||
return c.links.tls.listen(u, sintf)
|
||||
case "unix":
|
||||
return c.links.unix.listen(u, sintf)
|
||||
default:
|
||||
return nil, fmt.Errorf("unrecognised scheme %q", u.Scheme)
|
||||
}
|
||||
}
|
||||
|
||||
// Address gets the IPv6 address of the Yggdrasil node. This is always a /128
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue