forked from cryptix/goSam
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
325 lines (294 loc) · 7.76 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<html>
<head>
<title>
goSam
</title>
<meta name="author" content="eyedeekay" />
<meta name="description" content="goSam" />
<meta name="keywords" content="master" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="showhider.css" />
</head>
<body>
<div id="navbar">
<a href="#shownav">
Show navigation
</a>
<div id="shownav">
<div id="hidenav">
<ul>
<li>
<a href="..">
Up one level ^
</a>
</li>
<li>
<a href="index.html">
index
</a>
</li>
<li>
<a href="CONTRIBUTING.html">
CONTRIBUTING
</a>
</li>
</ul>
<br>
<a href="#hidenav">
Hide Navigation
</a>
</div>
</div>
</div>
<a id="returnhome" href="/">
/
</a>
<h1>
goSam
</h1>
<p>
A go library for using the
<a href="https://geti2p.net/en/">
I2P
</a>
Simple Anonymous
Messaging (
<a href="https://geti2p.net/en/docs/api/samv3">
SAM version 3.0
</a>
) bridge. It
has support for all streaming features SAM version 3.2.
</p>
<p>
STATUS: This project is maintained. I will respond to issues, pull requests, and feature requests within a few days. I am primarily maintaining functionality. This is widely used and easy to use, but thusfar, mostly by me. It sees a lot of testing and no breaking changes to the API are expected.
</p>
<h2>
Installation
</h2>
<pre><code>go get github.com/eyedeekay/goSam
</code></pre>
<h2>
Using it for HTTP Transport
</h2>
<p>
<code>
Client.Dial
</code>
implements
<code>
net.Dial
</code>
so you can use go’s library packages like http.
</p>
<pre><code class="language-go">package main
import (
"io"
"log"
"net/http"
"os"
"github.com/cryptix/goSam"
)
func main() {
// create a default sam client
sam, err := goSam.NewDefaultClient()
checkErr(err)
log.Println("Client Created")
// create a transport that uses SAM to dial TCP Connections
tr := &http.Transport{
Dial: sam.Dial,
}
// create a client using this transport
client := &http.Client{Transport: tr}
// send a get request
resp, err := client.Get("http://stats.i2p/")
checkErr(err)
defer resp.Body.Close()
log.Printf("Get returned %+v\n", resp)
// create a file for the response
file, err := os.Create("stats.html")
checkErr(err)
defer file.Close()
// copy the response to the file
_, err = io.Copy(file, resp.Body)
checkErr(err)
log.Println("Done.")
}
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}
</code></pre>
<h3>
Using SAM by default, as a proxy for all HTTP Clients used by a Go application
</h3>
<p>
This will make the SAM transport dialer the default for all HTTP clients.
</p>
<pre><code class="language-go">package main
import (
"io"
"log"
"net/http"
"os"
"github.com/cryptix/goSam"
)
func main() {
sam, err := goSam.NewDefaultClient()
checkErr(err)
log.Println("Client Created")
// create a transport that uses SAM to dial TCP Connections
httpClient := &http.Client{
Transport: &http.Transport{
Dial: sam.Dial,
},
}
http.DefaultClient = httpClient
return nil
}
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}
</code></pre>
<h2>
Using it as a SOCKS proxy
</h2>
<p>
<code>
client
</code>
also implements a resolver compatible with
<a href="https://github.com/getlantern/go-socks5">
<code>
getlantern/go-socks5
</code>
</a>
,
making it very easy to implement a SOCKS5 server.
</p>
<pre><code class="language-go">package main
import (
"flag"
"github.com/eyedeekay/goSam"
"github.com/getlantern/go-socks5"
"log"
)
var (
samaddr = flag.String("sam", "127.0.0.1:7656", "SAM API address to use")
socksaddr = flag.String("socks", "127.0.0.1:7675", "SOCKS address to use")
)
func main() {
sam, err := goSam.NewClient(*samaddr)
if err != nil {
panic(err)
}
log.Println("Client Created")
// create a transport that uses SAM to dial TCP Connections
conf := &socks5.Config{
Dial: sam.DialContext,
Resolver: sam,
}
server, err := socks5.New(conf)
if err != nil {
panic(err)
}
// Create SOCKS5 proxy on localhost port 8000
if err := server.ListenAndServe("tcp", *socksaddr); err != nil {
panic(err)
}
}
</code></pre>
<h3>
.deb package
</h3>
<p>
A package for installing this on Debian is buildable, and a version for Ubuntu
is available as a PPA and mirrored via i2p. To build the deb package, from the
root of this repository with the build dependencies installed(git, i2p, go,
debuild) run the command
</p>
<pre><code> debuild -us -uc
</code></pre>
<p>
to produce an unsigned deb for personal use only. For packagers,
</p>
<pre><code> debuild -S
</code></pre>
<p>
will produce a viable source package for use with Launchpad PPA’s and other
similar systems.
</p>
<h3>
TODO
</h3>
<ul>
<li>
Improve recovery on failed sockets
</li>
<li>
Implement
<code>
STREAM FORWARD
</code>
</li>
<li>
Implement datagrams (Repliable and Anon)
</li>
</ul>
<div id="sourcecode">
<span id="sourcehead">
<strong>
Get the source code:
</strong>
</span>
<ul>
<li>
<a href="https://github.com/eyedeekay/goSam">
Source Repository: (https://github.com/eyedeekay/goSam)
</a>
</li>
</ul>
</div>
<div>
<a href="#show">
Show license
</a>
<div id="show">
<div id="hide">
<pre><code>The MIT License (MIT)
Copyright (c) 2014 Henry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
</code></pre>
<a href="#hide">
Hide license
</a>
</div>
</div>
</div>
<div>
<iframe src="https://snowflake.torproject.org/embed.html" width="320" height="240" frameborder="0" scrolling="no"></iframe>
</div>
<div>
<a href="https://geti2p.net/">
<img src="i2plogo.png"></img>
I2P
</a>
</div>
</body>
</html>