Skip to content

Commit b56d48b

Browse files
committed
Bumped v0.5.10
Signed-off-by: Vishal Rana <[email protected]>
1 parent f9351d2 commit b56d48b

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE = labstack/tunnel
2-
VERSION = 0.5.9
2+
VERSION = 0.5.10
33

44
publish:
55
git tag v$(VERSION)

cmd/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
version = "v0.5.9"
10+
version = "v0.5.10"
1111
)
1212

1313
var versionCmd = &cobra.Command{

daemon/connection.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type (
4242
reconnectChan chan error
4343
stopChan chan bool
4444
started bool
45+
stopped bool
4546
retries time.Duration
4647
Header *Header
4748
ID string `json:"id"`
@@ -91,11 +92,6 @@ func (s *Server) newConnection(req *ConnectRequest) (c *Connection, err error) {
9192
acceptChan: make(chan net.Conn),
9293
reconnectChan: make(chan error),
9394
stopChan: make(chan bool),
94-
Header: &Header{
95-
ID: id,
96-
Key: viper.GetString("api_key"),
97-
Target: req.Address,
98-
},
9995
ID: id,
10096
TargetAddress: req.Address,
10197
RemoteHost: "0.0.0.0",
@@ -124,7 +120,12 @@ func (s *Server) newConnection(req *ConnectRequest) (c *Connection, err error) {
124120
if c.Configuration.Protocol != ProtocolHTTPS {
125121
c.RemotePort = 0
126122
}
127-
c.Header.Name = c.Name
123+
c.Header = &Header{
124+
ID: id,
125+
Name: c.Name,
126+
Key: viper.GetString("api_key"),
127+
Target: req.Address,
128+
}
128129
return
129130
}
130131

@@ -199,28 +200,35 @@ RECONNECT:
199200
// Remote listener
200201
l, err := sc.Listen("tcp", fmt.Sprintf("%s:%d", c.RemoteHost, c.RemotePort))
201202
if err != nil {
202-
log.Errorf("failed to listen on remote host: %v", err)
203+
c.startChan <- fmt.Errorf("failed to listen on remote host: %v", err)
204+
return
205+
}
206+
if err = c.server.findConnection(c); err != nil {
207+
c.startChan <- fmt.Errorf("failed to find connection: %v", err)
203208
return
204209
}
205210
// Note: Don't close the listener as it prevents closing the underlying connection
206211
c.retries = 0
207212
if !c.started {
208213
c.started = true
209-
c.startChan <- c.server.findConnection(c)
214+
c.startChan <- nil
210215
}
216+
connections[c.ID] = c
211217
log.Infof("connection %s is online", c.Name)
212218

213219
// Close
214220
defer func() {
215221
log.Infof("closing connection: %s", c.Name)
222+
delete(connections, c.ID);
216223
defer sc.Close()
217224
}()
218225

219226
// Accept connections
220227
go func() {
221228
for {
222229
in, err := l.Accept()
223-
if err != nil {
230+
if err != nil && !c.stopped {
231+
log.Error(err)
224232
c.reconnectChan <- err
225233
return
226234
}
@@ -232,6 +240,7 @@ RECONNECT:
232240
for {
233241
select {
234242
case <-c.stopChan:
243+
c.stopped = true
235244
return
236245
case in := <-c.acceptChan:
237246
go c.handle(in)

daemon/server.go

+11-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package daemon
22

33
import (
44
"errors"
5-
"fmt"
65
"github.com/fsnotify/fsnotify"
76
"github.com/labstack/gommon/log"
87
"github.com/spf13/viper"
@@ -17,8 +16,7 @@ import (
1716

1817
type (
1918
Server struct {
20-
resty *resty.Client
21-
Connections map[string]*Connection
19+
resty *resty.Client
2220
}
2321

2422
Protocol string
@@ -54,6 +52,10 @@ const (
5452
ProtocolTLS = "tls"
5553
)
5654

55+
var (
56+
connections = map[string]*Connection{}
57+
)
58+
5759
func (s *Server) Connect(req *ConnectRequest, rep *ConnectReply) (err error) {
5860
c, err := s.newConnection(req)
5961
if err != nil {
@@ -64,15 +66,17 @@ func (s *Server) Connect(req *ConnectRequest, rep *ConnectReply) (err error) {
6466
}
6567

6668
func (s *Server) PS(req *PSRequest, rep *PSReply) (err error) {
67-
for _, c := range s.Connections {
69+
for _, c := range connections {
6870
rep.Connections = append(rep.Connections, c)
6971
}
7072
return nil
7173
}
7274

7375
func (s *Server) RM(req *RMRequest, rep *RMReply) error {
74-
if c, ok := s.Connections[req.Name]; ok {
75-
c.stop()
76+
for _, c := range connections {
77+
if c.Name == req.Name {
78+
c.stop()
79+
}
7680
}
7781
return nil
7882
}
@@ -87,10 +91,7 @@ func Start() {
8791
})
8892
r.SetHeader("Content-Type", "application/json")
8993
r.SetHeader("User-Agent", "tunnel/client")
90-
s := &Server{
91-
resty: r,
92-
Connections: map[string]*Connection{},
93-
}
94+
s := &Server{resty: r}
9495
rpc.Register(s)
9596

9697
// Shutdown hook
@@ -127,21 +128,5 @@ func (s *Server) findConnection(c *Connection) (err error) {
127128
if res.IsError() {
128129
return errors.New(e.Message)
129130
}
130-
s.Connections[c.Name] = c
131-
return
132-
}
133-
134-
func (s *Server) deleteAll() (err error) {
135-
log.Warnf("removing all connections")
136-
e := new(Error)
137-
res, err := s.resty.R().
138-
SetError(e).
139-
Delete("/connections")
140-
if err != nil {
141-
return
142-
}
143-
if res.IsError() {
144-
return fmt.Errorf("failed to delete all connections")
145-
}
146131
return
147132
}

0 commit comments

Comments
 (0)