Skip to content

Commit 141258b

Browse files
committed
tests and simple benchmarks working
1 parent 860d01e commit 141258b

File tree

13 files changed

+312
-179
lines changed

13 files changed

+312
-179
lines changed

README.md

Lines changed: 83 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
# chisel
22

3+
<!--
34
![chisel](https://cloud.githubusercontent.com/assets/633843/6539989/7ec2d6ac-c4db-11e4-8648-6d2a462ded81.jpg)
5+
-->
46

57
Chisel is an HTTP client and server which acts as a TCP proxy. Chisel useful in situations where you only have access to HTTP, for example – behind a corporate firewall. Chisel is very similar to [crowbar](https://github.com/q3k/crowbar) though achieves **much** higher [performance](#performance). **Warning** This is beta software.
68

9+
![overview](https://docs.google.com/drawings/d/1p53VWxzGNfy8rjr-mW8pvisJmhkoLl82vAgctO_6f1w/pub?w=960&h=720)
10+
711
### Install
812

9-
Server
13+
**Binaries**
1014

11-
```
12-
$ go get -v github.com/jpillora/chisel/chiseld
13-
```
15+
See [Releases](releases/)
1416

15-
Forwarder
17+
**Source**
1618

1719
```
20+
# Server
21+
$ go get -v github.com/jpillora/chisel/chiseld
22+
# Client
1823
$ go get -v github.com/jpillora/chisel/chisel-forward
1924
```
2025

@@ -54,23 +59,27 @@ default proxy is pointing at http://example.com.
5459
```
5560
$ chiseld --help
5661
57-
Usage: chiseld [--host 0.0.0.0] [--port 8080] [--auth AUTH] [--proxy PROXY]
62+
Usage: chiseld [options]
63+
64+
Options:
65+
66+
--host, Defines the HTTP listening host – the network interface
67+
(defaults to 0.0.0.0). You may also set the HOST environment
68+
variable.
69+
70+
--port, Defines the HTTP listening port (defaults to 8080). You
71+
may also set the PORT environment variable.
5872
59-
host defines the HTTP listening host – the
60-
network interface (defaults to 0.0.0.0). You
61-
may also set the HOST environment variable.
73+
--auth, Specifies the exact authentication string the client must
74+
provide to attain access. You may also set the AUTH environment
75+
variable.
6276
63-
port defines the HTTP listening port (defaults
64-
to 8080). This option falls back to the PORT
65-
environment variable.
77+
--proxy, Specifies the default proxy target to use when chiseld
78+
receives a normal HTTP request.
6679
67-
auth specifies the authentication string
68-
the client must provide to attain access. This
69-
option falls back to the AUTH environment variable.
80+
-v, Enable verbose logging
7081
71-
proxy specifies the default proxy target to use
72-
when chiseld receives a normal HTTP request. This
73-
option falls back to the PROXY environment variable.
82+
--version, Display version
7483
7584
Read more:
7685
https://github.com/jpillora/chisel
@@ -79,18 +88,16 @@ $ chiseld --help
7988
```
8089
$ chisel-forward --help
8190
82-
Usage: chisel-forward [--auth AUTH] server remote [remote] [remote] ...
91+
Usage: chisel-forward [options] server remote [remote] [remote] ...
8392
84-
auth specifies the optional authentication string
85-
used by the server.
93+
server is the URL to the chiseld server.
8694
87-
server is the URL of the chiseld server.
95+
remotes are remote connections tunneled through the server, each of
96+
which come in the form:
8897
89-
remote is a remote connection via the server, which
90-
comes in the form:
9198
<local-host>:<local-port>:<remote-host>:<remote-port>
9299
93-
* Only remote-port is required.
100+
* remote-port is required.
94101
* local-port defaults to remote-port.
95102
* local-host defaults to 0.0.0.0 (all interfaces).
96103
* remote-host defaults to 0.0.0.0 (server localhost).
@@ -102,11 +109,20 @@ $ chisel-forward --help
102109
3000:google.com:80
103110
192.168.0.5:3000:google.com:80
104111
112+
Options:
113+
114+
--auth AUTH, Specifies the optional authentication string used by
115+
the server.
116+
117+
-v, Enable verbose logging
118+
119+
--version, Display version
120+
105121
Read more:
106122
https://github.com/jpillora/chisel
107123
```
108124

109-
Eventually, a programmatic API will be documented and available, if you're keen see the `main.go` files in each sub-package.
125+
See also: [programmatic API](https://github.com/jpillora/chisel/wiki/Programmatic-Usage).
110126

111127
### Security
112128

@@ -116,71 +132,63 @@ Currently, you can secure your traffic by using HTTPS, which can only be done by
116132

117133
With [crowbar](https://github.com/q3k/crowbar), a connection is tunnelled by repeatedly querying the server with updates. This results in a large amount of HTTP and TCP connection overhead. Chisel overcomes this using WebSockets combined with [Yamux](https://github.com/hashicorp/yamux) to create hundreds of SDPY/HTTP2 like logical connections, resulting in **one** TCP connection per client.
118134

119-
In this unscientific test, we have:
120-
121-
```
122-
curl -> http tunnel client -> http tunnel server -> file server
123-
```
124-
125-
*Tab 1 (local file server)*
135+
In this simple benchmark, we have:
126136

127137
```
128-
$ npm i -g serve
129-
$ serve -p 4000
138+
(direct)
139+
.--------------->----------------.
140+
/ chisel chisel \
141+
request--->client:2001--->server:2002---->fileserver:3000
142+
\ /
143+
'--> crowbar:4001--->crowbar:4002'
144+
client server
130145
```
131146

132-
*Tab 2 (tunnel server)*
147+
Note, we're using an in-memory "file" server on localhost for these tests
133148

134-
```
135-
$ echo -ne "foo:bar" > userfile
136-
$ crowbard -listen="0.0.0.0:8080" -userfile=./userfile
137-
```
138-
139-
*Tab 3 (tunnel client)*
149+
*direct*
140150

141151
```
142-
$ crowbar-forward -local=0.0.0.0:3000 -server http://localhost:8080 -remote localhost:4000 -username foo -password bar
152+
:3000 => 1 bytes in 1.008883ms
153+
:3000 => 10 bytes in 543.198µs
154+
:3000 => 100 bytes in 675.957µs
155+
:3000 => 1000 bytes in 584.13µs
156+
:3000 => 10000 bytes in 580.56µs
157+
:3000 => 100000 bytes in 743.902µs
158+
:3000 => 1000000 bytes in 1.962673ms
159+
:3000 => 10000000 bytes in 19.192986ms
160+
:3000 => 100000000 bytes in 158.428239ms
143161
```
144162

145-
*Tab 4 (transfer test)*
146-
147-
```
148-
$ time curl -s "127.0.0.1:3000/largefile.bin" > /dev/null
149-
74.74 real 2.37 user 6.74 sys
150-
```
151-
152-
Here, we see `largefile.bin` (~200MB) is transferred in **1m14s** (along with high CPU utilisation).
153-
154-
Enter `chisel`, lets swap in `chiseld` and `chisel-forward`
155-
156-
*Tab 2 (tunnel server)*
163+
`chisel`
157164

158165
```
159-
$ chiseld --auth foo
166+
:2001 => 1 bytes in 1.334661ms
167+
:2001 => 10 bytes in 807.797µs
168+
:2001 => 100 bytes in 763.728µs
169+
:2001 => 1000 bytes in 1.029811ms
170+
:2001 => 10000 bytes in 840.247µs
171+
:2001 => 100000 bytes in 1.647748ms
172+
:2001 => 1000000 bytes in 3.495904ms
173+
:2001 => 10000000 bytes in 22.298904ms
174+
:2001 => 100000000 bytes in 255.410448ms
160175
```
161176

162-
*Tab 3 (tunnel client)*
177+
`crowbar`
163178

164179
```
165-
$ chisel-forward --auth foo localhost:8080 3000:4000
166-
2015/02/27 16:13:43 Connected to http://localhost:8080
167-
2015/02/27 16:13:43 Proxy 0.0.0.0:3000 => 0.0.0.0:4000 enabled
180+
:4001 => 1 bytes in 3.335797ms
181+
:4001 => 10 bytes in 1.453007ms
182+
:4001 => 100 bytes in 1.811727ms
183+
:4001 => 1000 bytes in 1.621525ms
184+
:4001 => 10000 bytes in 5.20729ms
185+
:4001 => 100000 bytes in 38.461926ms
186+
:4001 => 1000000 bytes in 358.784864ms
187+
:4001 => 10000000 bytes in 3.603206487s
188+
:4001 => 100000000 bytes in 36.332395213s
168189
```
169190

170-
And now we'll run the test again
171-
172-
```
173-
$ time curl -s "127.0.0.1:3000/largefile.bin" > /dev/null
174-
0.60 real 0.05 user 0.14 sys
175-
```
176-
177-
Here, the same file was transferred in **0.6s**
178-
179-
*Note: Real benchmarks are on the Todo*
180-
181-
### Overview
182-
183-
![overview](https://docs.google.com/drawings/d/1p53VWxzGNfy8rjr-mW8pvisJmhkoLl82vAgctO_6f1w/pub?w=960&h=720)
191+
See [test/](tree/master/test/)
184192

185193
### Known Issues
186194

@@ -213,7 +221,7 @@ Here, the same file was transferred in **0.6s**
213221

214222
#### MIT License
215223

216-
Copyright © 2014 Jaime Pillora &lt;[email protected]&gt;
224+
Copyright © 2015 Jaime Pillora &lt;[email protected]&gt;
217225

218226
Permission is hereby granted, free of charge, to any person obtaining
219227
a copy of this software and associated documentation files (the

chisel-forward/client/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package client
1+
package chiselclient
22

33
import (
44
"errors"
@@ -26,7 +26,7 @@ type Client struct {
2626
runningc chan error
2727
}
2828

29-
func NewClient(auth, server string, remotes []string) (*Client, error) {
29+
func NewClient(auth, server string, remotes ...string) (*Client, error) {
3030

3131
//apply default scheme
3232
if !strings.HasPrefix(server, "http") {
@@ -95,7 +95,7 @@ func (c *Client) start() {
9595
//proxies all use this function
9696
openStream := func() (net.Conn, error) {
9797
if c.session == nil || c.session.IsClosed() {
98-
return nil, c.Errorf("no c.session")
98+
return nil, c.Errorf("no session available")
9999
}
100100
stream, err := c.session.Open()
101101
if err != nil {
@@ -184,5 +184,8 @@ func (c *Client) Wait() error {
184184
//Close manual stops the client
185185
func (c *Client) Close() error {
186186
c.running = false
187+
if c.session == nil {
188+
return nil
189+
}
187190
return c.session.Close()
188191
}

chisel-forward/client/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package client
1+
package chiselclient
22

33
import (
44
"encoding/binary"

chisel-forward/main.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ import (
99
"github.com/jpillora/chisel/chisel-forward/client"
1010
)
1111

12-
const help = `
12+
var VERSION string = "0.0.0-src" //set via ldflags
1313

14+
var help = `
1415
Usage: chisel-forward [options] server remote [remote] [remote] ...
1516
1617
server is the URL to the chiseld server.
1718
18-
remotes are remote connections tunneled through the server, each
19-
of which come in the form:
19+
remotes are remote connections tunneled through the server, each of
20+
which come in the form:
21+
2022
<local-host>:<local-port>:<remote-host>:<remote-port>
2123
22-
* Only remote-port is required.
24+
* remote-port is required.
2325
* local-port defaults to remote-port.
2426
* local-host defaults to 0.0.0.0 (all interfaces).
2527
* remote-host defaults to 0.0.0.0 (server localhost).
@@ -33,23 +35,31 @@ const help = `
3335
3436
Options:
3537
36-
--auth AUTH - auth specifies the optional authentication string
37-
used by the server.
38+
--auth AUTH, Specifies the optional authentication string used by
39+
the server.
40+
41+
-v, Enable verbose logging
3842
39-
-v enable verbose logging
43+
--version, Display version (` + VERSION + `)
4044
4145
Read more:
4246
https://github.com/jpillora/chisel
43-
4447
`
4548

4649
func main() {
4750
auth := flag.String("auth", "", "")
4851
verbose := flag.Bool("v", false, "")
52+
version := flag.Bool("version", false, "")
4953
flag.Usage = func() {
5054
fmt.Fprintf(os.Stderr, help)
5155
}
5256
flag.Parse()
57+
58+
if *version {
59+
fmt.Println(VERSION)
60+
os.Exit(1)
61+
}
62+
5363
args := flag.Args()
5464
if len(args) < 2 {
5565
log.Fatalf("A server and least one remote is required")
@@ -58,7 +68,7 @@ func main() {
5868
server := args[0]
5969
remotes := args[1:]
6070

61-
c, err := client.NewClient(*auth, server, remotes)
71+
c, err := chiselclient.NewClient(*auth, server, remotes...)
6272
if err != nil {
6373
log.Fatal(err)
6474
}

0 commit comments

Comments
 (0)