@@ -13,9 +13,8 @@ import (
13
13
)
14
14
15
15
type Server struct {
16
- auth string
17
- wsServer websocket.Server
18
- endpoints []* Endpoint
16
+ auth string
17
+ wsServer websocket.Server
19
18
}
20
19
21
20
func NewServer (auth string ) * Server {
@@ -89,13 +88,15 @@ func (s *Server) handleWS(ws *websocket.Conn) {
89
88
log .Fatalf ("Yamux server: %s" , err )
90
89
}
91
90
91
+ endpoints := make ([]* Endpoint , len (config .Remotes ))
92
+
92
93
// Create an endpoint for each required
93
94
for id , r := range config .Remotes {
94
95
addr := r .RemoteHost + ":" + r .RemotePort
95
96
e := NewEndpoint (id , addr )
96
97
go e .start ()
97
98
log .Printf ("Activate remote #%d %s" , id , r )
98
- s . endpoints = append ( s . endpoints , e )
99
+ endpoints [ id ] = e
99
100
}
100
101
101
102
for {
@@ -108,11 +109,11 @@ func (s *Server) handleWS(ws *websocket.Conn) {
108
109
log .Printf ("Session accept: %s" , err )
109
110
continue
110
111
}
111
- go s .handleStream (stream )
112
+ go s .handleStream (stream , endpoints )
112
113
}
113
114
}
114
115
115
- func (s * Server ) handleStream (stream net.Conn ) {
116
+ func (s * Server ) handleStream (stream net.Conn , endpoints [] * Endpoint ) {
116
117
// extract endpoint id
117
118
b := make ([]byte , 2 )
118
119
n , err := stream .Read (b )
@@ -127,6 +128,6 @@ func (s *Server) handleStream(stream net.Conn) {
127
128
id := binary .BigEndian .Uint16 (b )
128
129
129
130
//then pipe
130
- e := s . endpoints [id ]
131
+ e := endpoints [id ]
131
132
e .session <- stream
132
133
}
0 commit comments