Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GoSF - Decentralizing the Web (again)

GoSF - Decentralizing the Web (again)

inconshreveable

February 27, 2014
Tweet

Other Decks in Technology

Transcript

  1. Why don’t you run your own • mail server (gmail)

    • file server (box, dropbox) • media streaming server (spotify, netflix) • web server (heroku, aws)
  2. • content (netflix/spotify) • cost • operational pain (everything else)

    • security • backups • updates • scale • deployment
  3. - Every home consumer and business circa 2000 “How do

    I connect more machines to the internet than my ISP gives me IP addresses?”
  4. The rise of NAT • ~15 years ago • Not

    enough IPv4 addresses, IPv6 not ready • Unilateral deployment • Not standardized
  5. 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
  6. –Every web developer circa 2014 “How do I develop a

    service that receives webhooks from {API}?”
  7. 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
  8. Another use of ngrok • Run your own minecraft server.

    Instructions: • java -jar minecraft_server.jar • ngrok -proto=tcp 25565
  9. 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) 
 }
  10. 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)
 }
  11. 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
  12. 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
  13. Stream Multiplexing • Old, old idea • SSH, WebMUX (HTTPNG),

    BEEP, SPDY, HTTP2, TMP, SCP • SCTP • non-starter, because NATs
  14. 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
  15. 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
  16. 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)! }
  17. 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!
  18. 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
  19. 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()
 }()
  20. :( • Kernel/NIC multitasking is better • No standard (part

    of some other protocol) • Head-of-line-blocking • QUIC
  21. 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
  22. Forward • Standardize the protocols • C implementation /w bindings

    to other languages • Build more host-anywhere services