Share
Embed
Transcript
38 slides
-
Why don’t you run your own • mail server (gmail)
• file server (box, dropbox) • media streaming server (spotify, netflix) • web server (heroku, aws) -
• content (netflix/spotify) • cost • operational pain (everything else)
• security • backups • updates • scale • deployment -
- Every home consumer and business circa 2000 “How do
I connect more machines to the internet than my ISP gives me IP addresses?” -
The rise of NAT • ~15 years ago • Not
enough IPv4 addresses, IPv6 not ready • Unilateral deployment • Not standardized -
The Cost • No end-to-end connectivity on the internet •
Problems for every peer-to-peer protocol • No ordinary user can run their own mail/file/ media/* server • I can’t ssh into my laptop -
–Every web developer circa 2014 “How do I develop a
service that receives webhooks from {API}?” -
ngrok • Originally a port of localtunnel to learn Go
• Establishes a secure tunnel that proxies traffic from a public endpoint to your local machine • Good for building webhook consumers • ngrok 1234 • http://{random}.ngrok.com -> 127.0.0.1:1234 -
Another use of ngrok • Run your own minecraft server.
Instructions: • java -jar minecraft_server.jar • ngrok -proto=tcp 25565 -
func Dial(addr net.Addr) *Session! ! type Session {! ! ListenTCP(opts
*TCPOptions) (*Tunnel, error)! ! ListenHTTP(opts *HTTPOptions) (*Tunnel, error)! }! ! type Tunnel {! ! Addr() net.Addr! ! Accept (net.Conn, error)! ! Close (error) } -
go-tunnel l, err := net.Listen(“0.0.0.0:9090”)! ! for {! ! conn,
err := l.Accept()! ! handleConn(conn) } -
go-tunnel sess, err := tunnel.Dial(“v1.airlock.io:443”)! ! l, err := sess.ListenTCP(&proto.TCPOptions{!
! RemotePort: 9090,! }, nil)! ! for {! ! conn, err := l.Accept()! ! handleConn(conn) } -
Stream Multiplexing • Many “logical” connections on a single “physical”
connection • Basic idea • split streams into chunks • send chunks with a stream identifier • reassemble on the remote side -
Stream Multiplexing Hey, nice day out, what’s it like? Oh,
that’s great! I brought a picnic lunch. It’s sunny, but a little chilly Also, Knock knock Who’s there? Interrupting . . . Okay, I’ll meet you in the park at noon. Interrupting Cow Cool, I think I’ll join you, I could use some sun. MOOOO -
Stream Multiplexing • Old, old idea • SSH, WebMUX (HTTPNG),
BEEP, SPDY, HTTP2, TMP, SCP • SCTP • non-starter, because NATs -
Stream Multiplexing • Don’t build, steal: SPDYv3/HTTP2 framing layer 0
1 2 3! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+! | Length (16) | Type (8) | Flags (8) |! +-+-------------+---------------+-------------------------------+! |R| Stream Identifier (31) |! +-+-------------------------------------------------------------+! | Frame Payload (0...) ...! +---------------------------------------------------------------+ • Many frame types. So complicated. Much confusion. Remove some. Wow. • DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, CONTINUATION, GOAWAY, WINDOW_UPDATE • SYN, DATA, RST, GOAWAY, WINDOW_UPDATE -
Built as a library • muxado (github.com/inconshreveable/muxado) • Generic stream
multiplexing (only in Go, for now) • Great for tunneling • Also, great for RPC, it turns out -
muxado’s interfaces type Session interface {! ! Open() (Stream, error)!
! Accept() (Stream, error)! ! Close() (error)! } type Stream interface {! ! Read(p []byte) (int, error)! ! Write(p []byte) (int, error)! ! Close() (error)! } -
Aside: RPC • RPC - Open connection, send request, read
response • memcache, redis, *SQL, task queues, etc • Parallelism? • Open lots of connections! Put them in a pool! -
Aside: RPC • Smarter RPC • Open base connection, then
open many *streams* • No pooling, logical streams are cheap • Parallels to OS threads vs user-mode threads -
Aside: RPC sess, err := muxado.Dial(“10.1.1.101:4444”)! ! go func() {!
! stream, err := sess.Open()! ! n, err := stream.Write(“SELECT * FROM user”)! ! resp, err := stream.Read()! ! // do stuff with response! ! ! stream.Close() }()! ! go func() {! ! stream, err := sess.Open()! ! n, err := stream.Write(“SHOW PROCESSLIST”)! ! resp, err := stream.Read()! ! ! // do stuff with response! ! ! stream.Close() }() -
:( • Kernel/NIC multitasking is better • No standard (part
of some other protocol) • Head-of-line-blocking • QUIC -
What to do with this power? • Start de-centralizing the
web • Build applications that anyone can deploy on any internet-connected machine • Allow users to optionally bind to public tunnel addresses • in addition to binding to local ports, of course -
srvdir • alpha • first go-tunnel project • SimpleHTTPServer with
public URLs • https://www.srvdir.net -
Forward • Standardize the protocols • C implementation /w bindings
to other languages • Build more host-anywhere services -
Addressing the unaddressable • NAT • Heroku • TOR •
Embedded • Mobile • ???