mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
Merge branch 'develop' into future
This commit is contained in:
commit
a4a346c498
@ -189,22 +189,43 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
|
|||||||
}, errors.New("Failed to add peer")
|
}, errors.New("Failed to add peer")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
a.AddHandler("removePeer", []string{"port"}, func(in Info) (Info, error) {
|
a.AddHandler("disconnectPeer", []string{"port"}, func(in Info) (Info, error) {
|
||||||
port, err := strconv.ParseInt(fmt.Sprint(in["port"]), 10, 64)
|
port, err := strconv.ParseInt(fmt.Sprint(in["port"]), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Info{}, err
|
return Info{}, err
|
||||||
}
|
}
|
||||||
if a.core.DisconnectPeer(uint64(port)) == nil {
|
if a.core.DisconnectPeer(uint64(port)) == nil {
|
||||||
return Info{
|
return Info{
|
||||||
"removed": []string{
|
"disconnected": []string{
|
||||||
fmt.Sprint(port),
|
fmt.Sprint(port),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
} else {
|
} else {
|
||||||
return Info{
|
return Info{
|
||||||
"not_removed": []string{
|
"not_disconnected": []string{
|
||||||
fmt.Sprint(port),
|
fmt.Sprint(port),
|
||||||
},
|
},
|
||||||
|
}, errors.New("Failed to disconnect peer")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
a.AddHandler("removePeer", []string{"uri", "[interface]"}, func(in Info) (Info, error) {
|
||||||
|
// Set sane defaults
|
||||||
|
intf := ""
|
||||||
|
// Has interface been specified?
|
||||||
|
if itf, ok := in["interface"]; ok {
|
||||||
|
intf = itf.(string)
|
||||||
|
}
|
||||||
|
if a.core.RemovePeer(in["uri"].(string), intf) == nil {
|
||||||
|
return Info{
|
||||||
|
"removed": []string{
|
||||||
|
in["uri"].(string),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
} else {
|
||||||
|
return Info{
|
||||||
|
"not_removed": []string{
|
||||||
|
in["uri"].(string),
|
||||||
|
},
|
||||||
}, errors.New("Failed to remove peer")
|
}, errors.New("Failed to remove peer")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -448,12 +448,31 @@ func (c *Core) AddPeer(addr string, sintf string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemovePeer is not implemented yet.
|
|
||||||
func (c *Core) RemovePeer(addr string, sintf string) error {
|
func (c *Core) RemovePeer(addr string, sintf string) error {
|
||||||
// TODO: Implement a reverse of AddPeer, where we look up the port number
|
if sintf == "" {
|
||||||
// based on the addr and sintf, disconnect it and then remove it from the
|
for i, peer := range c.config.Current.Peers {
|
||||||
// peers list so we don't reconnect to it later
|
if peer == addr {
|
||||||
return errors.New("not implemented")
|
c.config.Current.Peers = append(c.config.Current.Peers[:i], c.config.Current.Peers[i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if _, ok := c.config.Current.InterfacePeers[sintf]; ok {
|
||||||
|
for i, peer := range c.config.Current.InterfacePeers[sintf] {
|
||||||
|
if peer == addr {
|
||||||
|
c.config.Current.InterfacePeers[sintf] = append(c.config.Current.InterfacePeers[sintf][:i], c.config.Current.InterfacePeers[sintf][i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ports := c.peers.ports.Load().(map[switchPort]*peer)
|
||||||
|
for p, peer := range ports {
|
||||||
|
if addr == peer.intf.name {
|
||||||
|
c.peers.removePeer(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallPeer calls a peer once. This should be specified in the peer URI format,
|
// CallPeer calls a peer once. This should be specified in the peer URI format,
|
||||||
|
Loading…
Reference in New Issue
Block a user