Files
sam-forwarder/README.md.asc

84 lines
3.4 KiB
Plaintext
Raw Normal View History

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
2018-07-26 17:50:46 -04:00
# sam-forwarder
Forward a local port to i2p over the SAM API.
## building
Just:
make deps build
and it will be in the folder ./bin/
## usage
2018-07-27 12:37:11 -04:00
./bin/ephsite -host=host -port=port
So, to serve an eepSite version of a local service on port 8080 -
2018-07-27 12:37:11 -04:00
./bin/ephsite -host=127.0.0.1 -port=8080
2018-07-26 23:15:27 -04:00
## Quick-And-Dirty i2p-enabled golang web applications
Normal web applications can easily add the ability to serve itself over i2p by
importing and configuring this forwarding doodad. Wherever it takes the argument
for the web server's listening host and/or port, pass that same host and/or port
to a new instance of the "SAMForwarder" and then run the "Serve" function of the
SAMForwarder as a gorouting. This simply forwards the running service to the i2p
network, it doesn't do any filtering, and if your application establishes
out-of-band connections, those may escape. Also, if your application is
listening on all addresses, it will be visible from the local network.
Here's a simple example with a simple static file server:
```Diff
2018-07-27 12:37:11 -04:00
package main package main
import ( import (
"flag" "flag"
"log" "log"
"net/http" "net/http"
) )
> import "github.com/eyedeekay/sam-forwarder"
>
func main() { func main() {
port := flag.String("p", "8100", "port to serve on") port := flag.String("p", "8100", "port to serve on")
directory := flag.String("d", ".", "the directory of static file to host") directory := flag.String("d", ".", "the directory of static file to host")
flag.Parse() flag.Parse()
>
> forwarder, err := samforwarder.NewSAMForwarderFromOptions(
> samforwarder.SetHost("127.0.0.1"),
> samforwarder.SetPort(*port),
> samforwarder.SetSAMHost("127.0.0.1"),
> samforwarder.SetSAMPort("7656"),
> samforwarder.SetName("staticfiles"),
> )
> if err != nil {
> log.Fatal(err.Error())
> }
> go forwarder.Serve()
http.Handle("/", http.FileServer(http.Dir(*directory))) http.Handle("/", http.FileServer(http.Dir(*directory)))
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port) log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe("127.0.0.1:"+*port, nil)) log.Fatal(http.ListenAndServe("127.0.0.1:"+*port, nil))
} }
2018-07-26 23:15:27 -04:00
```
[This tiny file server taken from here and used for this example](https://gist.github.com/paulmach/7271283)
-----BEGIN PGP SIGNATURE-----
2018-07-28 03:41:33 -04:00
iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAltcHiwACgkQ11wDs5te
FOHXBggAqZsfX7T/7sALmhxFVEHzkK+X8Ud4AoUPjxkDjUXAEaMgIK9Pg8xeWtUB
ExzQH8TzDgcnZhXWpYkNiaVtzWSuu/YV62if4hrlZVo/WIeNjLc87R31RRCYl+ne
5IPoFdxDwh/k8VN5/skxNaSoYIcZMKrd5siu2PWSGt4Te+WDadBgev9/T+hXvZce
HfXlHtpgafn1LDLKDHVVwnPBWMYOPWus0HgYQS+xA56efeAknyGCAxXlEPkoSp9E
GoQdZ38hBThIckcS5gfKwZxUDd9LzLs+FT88Nvdi2/hOXSdvKOs8lX1eyG0GxlYf
JcFmbju+JbIqSpaVNR9FF8wgiBBcuA==
=lxSl
-----END PGP SIGNATURE-----