From c60dd42baa6b832923128c1fd637e480c883841e Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sun, 23 May 2021 21:51:09 -0500 Subject: [PATCH] cleanup --- src/core/api.go | 17 +++-------------- src/core/tcp.go | 18 ++---------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/core/api.go b/src/core/api.go index df39046c..f28b592a 100644 --- a/src/core/api.go +++ b/src/core/api.go @@ -103,24 +103,13 @@ func (c *Core) GetSessions() []Session { return sessions } +// 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) } -// ListenTCP starts a new TCP listener. The input URI should match that of the -// "Listen" configuration item, e.g. -// tcp://a.b.c.d:e -func (c *Core) xListenTCP(uri string, metric uint8) (*TcpListener, error) { - return c.links.tcp.listen(uri, nil, metric) -} - -// ListenTLS starts a new TLS listener. The input URI should match that of the -// "Listen" configuration item, e.g. -// tls://a.b.c.d:e -func (c *Core) xListenTLS(uri string, metric uint8) (*TcpListener, error) { - return c.links.tcp.listen(uri, c.links.tcp.tls.forListener, metric) -} - // Address gets the IPv6 address of the Yggdrasil node. This is always a /128 // address. The IPv6 address is only relevant when the node is operating as an // IP router and often is meaningless when embedded into an application, unless diff --git a/src/core/tcp.go b/src/core/tcp.go index 66ac7af9..2cba8182 100644 --- a/src/core/tcp.go +++ b/src/core/tcp.go @@ -113,22 +113,8 @@ func (t *tcp) init(l *links) error { if err != nil { t.links.core.log.Errorln("Failed to parse listener: listener", listenaddr, "is not correctly formatted, ignoring") } - var metric uint8 // TODO parse from url - if ms := u.Query()["metric"]; len(ms) == 1 { - m64, _ := strconv.ParseUint(ms[0], 10, 8) - metric = uint8(m64) - } - switch u.Scheme { - case "tcp": - if _, err := t.listen(u.Host, nil, metric); err != nil { - return err - } - case "tls": - if _, err := t.listen(u.Host, t.tls.forListener, metric); err != nil { - return err - } - default: - t.links.core.log.Errorln("Failed to add listener: listener", u.String(), "is not correctly formatted, ignoring") + if _, err := t.listenURL(u, ""); err != nil { + return err } }