Skip to content

Commit 0334966

Browse files
committed
endpoints per ws, added diagram
1 parent b4408a7 commit 0334966

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Chisel is TCP proxy tunnelled over HTTP and Websockets
44

5+
![how it works](https://docs.google.com/drawings/d/1p53VWxzGNfy8rjr-mW8pvisJmhkoLl82vAgctO_6f1w/pub?w=960&h=720)
6+
57
### Install
68

79
Server

chiseld/server/server.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
)
1414

1515
type Server struct {
16-
auth string
17-
wsServer websocket.Server
18-
endpoints []*Endpoint
16+
auth string
17+
wsServer websocket.Server
1918
}
2019

2120
func NewServer(auth string) *Server {
@@ -89,13 +88,15 @@ func (s *Server) handleWS(ws *websocket.Conn) {
8988
log.Fatalf("Yamux server: %s", err)
9089
}
9190

91+
endpoints := make([]*Endpoint, len(config.Remotes))
92+
9293
// Create an endpoint for each required
9394
for id, r := range config.Remotes {
9495
addr := r.RemoteHost + ":" + r.RemotePort
9596
e := NewEndpoint(id, addr)
9697
go e.start()
9798
log.Printf("Activate remote #%d %s", id, r)
98-
s.endpoints = append(s.endpoints, e)
99+
endpoints[id] = e
99100
}
100101

101102
for {
@@ -108,11 +109,11 @@ func (s *Server) handleWS(ws *websocket.Conn) {
108109
log.Printf("Session accept: %s", err)
109110
continue
110111
}
111-
go s.handleStream(stream)
112+
go s.handleStream(stream, endpoints)
112113
}
113114
}
114115

115-
func (s *Server) handleStream(stream net.Conn) {
116+
func (s *Server) handleStream(stream net.Conn, endpoints []*Endpoint) {
116117
// extract endpoint id
117118
b := make([]byte, 2)
118119
n, err := stream.Read(b)
@@ -127,6 +128,6 @@ func (s *Server) handleStream(stream net.Conn) {
127128
id := binary.BigEndian.Uint16(b)
128129

129130
//then pipe
130-
e := s.endpoints[id]
131+
e := endpoints[id]
131132
e.session <- stream
132133
}

0 commit comments

Comments
 (0)