mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
make the main library reconfiguration more actor-friendly
This commit is contained in:
parent
aa30c6cc98
commit
a3d4d8125b
9 changed files with 144 additions and 159 deletions
|
@ -21,11 +21,10 @@ import (
|
|||
)
|
||||
|
||||
type link struct {
|
||||
core *Core
|
||||
reconfigure chan chan error
|
||||
mutex sync.RWMutex // protects interfaces below
|
||||
interfaces map[linkInfo]*linkInterface
|
||||
tcp tcp // TCP interface support
|
||||
core *Core
|
||||
mutex sync.RWMutex // protects interfaces below
|
||||
interfaces map[linkInfo]*linkInterface
|
||||
tcp tcp // TCP interface support
|
||||
// TODO timeout (to remove from switch), read from config.ReadTimeout
|
||||
}
|
||||
|
||||
|
@ -61,7 +60,6 @@ func (l *link) init(c *Core) error {
|
|||
l.core = c
|
||||
l.mutex.Lock()
|
||||
l.interfaces = make(map[linkInfo]*linkInterface)
|
||||
l.reconfigure = make(chan chan error)
|
||||
l.mutex.Unlock()
|
||||
|
||||
if err := l.tcp.init(l); err != nil {
|
||||
|
@ -69,22 +67,18 @@ func (l *link) init(c *Core) error {
|
|||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
e := <-l.reconfigure
|
||||
tcpresponse := make(chan error)
|
||||
l.tcp.reconfigure <- tcpresponse
|
||||
if err := <-tcpresponse; err != nil {
|
||||
e <- err
|
||||
continue
|
||||
}
|
||||
e <- nil
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *link) reconfigure(e chan error) {
|
||||
defer close(e)
|
||||
tcpResponse := make(chan error)
|
||||
go l.tcp.reconfigure(tcpResponse)
|
||||
for err := range tcpResponse {
|
||||
e <- err
|
||||
}
|
||||
}
|
||||
|
||||
func (l *link) call(uri string, sintf string) error {
|
||||
u, err := url.Parse(uri)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue