Support reconnects

This commit is contained in:
Asim Aslam
2019-10-13 18:36:22 +01:00
parent d6c6e7815e
commit f77df51f60
4 changed files with 68 additions and 39 deletions

View File

@@ -777,6 +777,30 @@ func (t *tun) setupLink(node string) (*link, error) {
return link, nil
}
func (t *tun) setupLinks() {
for _, node := range t.options.Nodes {
// skip zero length nodes
if len(node) == 0 {
continue
}
// link already exists
if _, ok := t.links[node]; ok {
continue
}
// connect to node and return link
link, err := t.setupLink(node)
if err != nil {
log.Debugf("Tunnel failed to establish node link to %s: %v", node, err)
continue
}
// save the link
t.links[node] = link
}
}
// connect the tunnel to all the nodes and listen for incoming tunnel connections
func (t *tun) connect() error {
l, err := t.options.Transport.Listen(t.options.Address)
@@ -816,22 +840,8 @@ func (t *tun) connect() error {
}
}()
for _, node := range t.options.Nodes {
// skip zero length nodes
if len(node) == 0 {
continue
}
// connect to node and return link
link, err := t.setupLink(node)
if err != nil {
log.Debugf("Tunnel failed to establish node link to %s: %v", node, err)
continue
}
// save the link
t.links[node] = link
}
// setup links
t.setupLinks()
// process outbound messages to be sent
// process sends to all links
@@ -850,6 +860,8 @@ func (t *tun) Connect() error {
// already connected
if t.connected {
// setup links
t.setupLinks()
return nil
}