5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 11:51:37 +00:00

Be more verbose when a peer or listener is badly formatted

This commit is contained in:
Neil Alexander 2019-09-18 15:01:19 +01:00
parent a62e029e21
commit 846df4789a
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 15 additions and 6 deletions

View File

@ -91,15 +91,21 @@ func (c *Core) _addPeerLoop() {
// Add peers from the Peers section // Add peers from the Peers section
for _, peer := range current.Peers { for _, peer := range current.Peers {
go c.AddPeer(peer, "") // TODO: this should be acted and not in a goroutine? go func() {
time.Sleep(time.Second) if err := c.AddPeer(peer, ""); err != nil {
c.log.Errorln("Failed to add peer:", err)
}
}() // TODO: this should be acted and not in a goroutine?
} }
// Add peers from the InterfacePeers section // Add peers from the InterfacePeers section
for intf, intfpeers := range current.InterfacePeers { for intf, intfpeers := range current.InterfacePeers {
for _, peer := range intfpeers { for _, peer := range intfpeers {
go c.AddPeer(peer, intf) // TODO: this should be acted and not in a goroutine? go func() {
time.Sleep(time.Second) if err := c.AddPeer(peer, intf); err != nil {
c.log.Errorln("Failed to add peer:", err)
}
}() // TODO: this should be acted and not in a goroutine?
} }
} }

View File

@ -86,7 +86,7 @@ func (l *link) reconfigure() {
func (l *link) call(uri string, sintf string) error { func (l *link) call(uri string, sintf string) error {
u, err := url.Parse(uri) u, err := url.Parse(uri)
if err != nil { if err != nil {
return err return fmt.Errorf("peer %s is not correctly formatted (%s)", uri, err)
} }
pathtokens := strings.Split(strings.Trim(u.Path, "/"), "/") pathtokens := strings.Split(strings.Trim(u.Path, "/"), "/")
switch u.Scheme { switch u.Scheme {
@ -103,7 +103,7 @@ func (l *link) call(uri string, sintf string) error {
func (l *link) listen(uri string) error { func (l *link) listen(uri string) error {
u, err := url.Parse(uri) u, err := url.Parse(uri)
if err != nil { if err != nil {
return err return fmt.Errorf("listener %s is not correctly formatted (%s)", uri, err)
} }
switch u.Scheme { switch u.Scheme {
case "tcp": case "tcp":

View File

@ -85,6 +85,7 @@ func (t *tcp) init(l *link) error {
defer t.link.core.config.Mutex.RUnlock() defer t.link.core.config.Mutex.RUnlock()
for _, listenaddr := range t.link.core.config.Current.Listen { for _, listenaddr := range t.link.core.config.Current.Listen {
if listenaddr[:6] != "tcp://" { if listenaddr[:6] != "tcp://" {
t.link.core.log.Errorln("Failed to add listener: listener", listenaddr, "is not correctly formatted, ignoring")
continue continue
} }
if _, err := t.listen(listenaddr[6:]); err != nil { if _, err := t.listen(listenaddr[6:]); err != nil {
@ -103,6 +104,7 @@ func (t *tcp) reconfigure() {
if len(added) > 0 || len(deleted) > 0 { if len(added) > 0 || len(deleted) > 0 {
for _, a := range added { for _, a := range added {
if a[:6] != "tcp://" { if a[:6] != "tcp://" {
t.link.core.log.Errorln("Failed to add listener: listener", a, "is not correctly formatted, ignoring")
continue continue
} }
if _, err := t.listen(a[6:]); err != nil { if _, err := t.listen(a[6:]); err != nil {
@ -113,6 +115,7 @@ func (t *tcp) reconfigure() {
} }
for _, d := range deleted { for _, d := range deleted {
if d[:6] != "tcp://" { if d[:6] != "tcp://" {
t.link.core.log.Errorln("Failed to delete listener: listener", d, "is not correctly formatted, ignoring")
continue continue
} }
t.mutex.Lock() t.mutex.Lock()