mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Merge remote-tracking branch 'origin/develop' into getswitchqueues
This commit is contained in:
commit
2674e1cb8b
8 changed files with 203 additions and 125 deletions
|
@ -116,8 +116,14 @@ func (a *admin) init(c *Core, listenaddr string) {
|
|||
}
|
||||
return admin_info{"sessions": sessions}, nil
|
||||
})
|
||||
a.addHandler("addPeer", []string{"uri"}, func(in admin_info) (admin_info, error) {
|
||||
if a.addPeer(in["uri"].(string)) == nil {
|
||||
a.addHandler("addPeer", []string{"uri", "[interface]"}, func(in admin_info) (admin_info, error) {
|
||||
// Set sane defaults
|
||||
intf := ""
|
||||
// Has interface been specified?
|
||||
if itf, ok := in["interface"]; ok {
|
||||
intf = itf.(string)
|
||||
}
|
||||
if a.addPeer(in["uri"].(string), intf) == nil {
|
||||
return admin_info{
|
||||
"added": []string{
|
||||
in["uri"].(string),
|
||||
|
@ -394,12 +400,12 @@ func (a *admin) printInfos(infos []admin_nodeInfo) string {
|
|||
}
|
||||
|
||||
// addPeer triggers a connection attempt to a node.
|
||||
func (a *admin) addPeer(addr string) error {
|
||||
func (a *admin) addPeer(addr string, sintf string) error {
|
||||
u, err := url.Parse(addr)
|
||||
if err == nil {
|
||||
switch strings.ToLower(u.Scheme) {
|
||||
case "tcp":
|
||||
a.core.tcp.connect(u.Host)
|
||||
a.core.tcp.connect(u.Host, sintf)
|
||||
case "socks":
|
||||
a.core.tcp.connectSOCKS(u.Host, u.Path[1:])
|
||||
default:
|
||||
|
@ -411,7 +417,7 @@ func (a *admin) addPeer(addr string) error {
|
|||
if strings.HasPrefix(addr, "tcp:") {
|
||||
addr = addr[4:]
|
||||
}
|
||||
a.core.tcp.connect(addr)
|
||||
a.core.tcp.connect(addr, "")
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
|
@ -508,6 +514,8 @@ func (a *admin) getData_getSwitchPeers() []admin_nodeInfo {
|
|||
{"ip", net.IP(addr[:]).String()},
|
||||
{"coords", fmt.Sprint(coords)},
|
||||
{"port", elem.port},
|
||||
{"bytes_sent", atomic.LoadUint64(&peer.bytesSent)},
|
||||
{"bytes_recvd", atomic.LoadUint64(&peer.bytesRecvd)},
|
||||
}
|
||||
peerInfos = append(peerInfos, info)
|
||||
}
|
||||
|
@ -676,6 +684,16 @@ func (a *admin) getResponse_dot() []byte {
|
|||
newInfo.name = "?"
|
||||
newInfo.key = key
|
||||
newInfo.options = "fontname=\"sans serif\" style=dashed color=\"#999999\" fontcolor=\"#999999\""
|
||||
|
||||
coordsSplit := coordSlice(newInfo.key)
|
||||
if len(coordsSplit) != 0 {
|
||||
portStr := coordsSplit[len(coordsSplit)-1]
|
||||
portUint, err := strconv.ParseUint(portStr, 10, 64)
|
||||
if err == nil {
|
||||
newInfo.port = switchPort(portUint)
|
||||
}
|
||||
}
|
||||
|
||||
infos[key] = newInfo
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue