Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
go
for the paranoid network programmer
@feyeleanor
1go for the would-be network programmer http://slides.games-with-brains...
twitter://@feyeleanor
go for the would-be network programmer http://slides.games-with-brains.net/
high voltage
networking
concurrency
cryptography
go for the would-be network programmer http://slides.games-with-brains.ne...
http
4go for the would-be network programmer http://slides.games-with-brains.net/
package main
import (
. "fmt"
"net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
http.Handle...
package main
import (
. "fmt"
"net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
http.Handle...
package main
import (
. "fmt"
"net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
http.Handle...
package main
import (
. "fmt"
. "net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
package main
import (
. "fmt"
. ”net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
package main
import (
. "fmt"
. ”net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
package main
import (
. "fmt"
. ”net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
package main
import (
. "fmt"
. ”net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
package main
import (
. "fmt"
. ”net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
package main
import (
. "fmt"
. "net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
package main
import (
. "fmt"
. "net/http"
)
const MESSAGE = "hello world"
const ADDRESS = ":1024"
func main() {
HandleFun...
https
16go for the would-be network programmer http://slides.games-with-brains.net/
package main
import (
. "fmt"
. "net/http"
)
const ADDRESS = ":1025"
func main() {
message := "hello world"
HandleFunc("/h...
package main
import (
. "fmt"
. "net/http"
)
const ADDRESS = ":1025"
func main() {
message := "hello world"
HandleFunc("/h...
package main
import (
. "fmt"
. "net/http"
)
const ADDRESS = ":1025"
func main() {
message := "hello world"
HandleFunc("/h...
package main
import (
. "fmt"
. "net/http"
)
const ADDRESS = ":1025"
func main() {
message := "hello world"
HandleFunc("/h...
multiple http servers
21go for the would-be network programmer http://slides.games-with-brains.net/
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
import . "fmt"
import . "net/http"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r *Request) {
w....
package main
func Spawn(f ...func()) {
done := make(chan bool)
for _, s := range f {
go func(server func()) {
server()
don...
package main
func Spawn(f ...func()) {
done := make(chan bool)
for _, s := range f {
go func(server func()) {
server()
don...
package main
func Spawn(f ...func()) {
done := make(chan bool)
for _, s := range f {
go func(server func()) {
server()
don...
package main
func Spawn(f ...func()) {
done := make(chan bool)
for _, s := range f {
go func(server func()) {
server()
don...
package main
func Spawn(f ...func()) {
done := make(chan bool)
for _, s := range f {
go func(server func()) {
server()
don...
package main
func Spawn(f ...func()) {
done := make(chan bool)
for _, s := range f {
go func(server func()) {
server()
don...
package main
func Spawn(f ...func()) {
done := make(chan bool)
for _, s := range f {
go func(server func()) {
server()
don...
waitgroups
40go for the would-be network programmer http://slides.games-with-brains.net/
package main
import . "fmt"
import . "net/http"
import "sync"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r ...
package main
import . "fmt"
import . "net/http"
import "sync"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r ...
package main
import . "fmt"
import . "net/http"
import "sync"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r ...
package main
import . "fmt"
import . "net/http"
import "sync"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r ...
package main
import . "fmt"
import . "net/http"
import "sync"
func main() {
HandleFunc("/hello", func(w ResponseWriter, r ...
package main
import . "fmt"
import . "net/http"
import "sync"
var servers sync.WaitGroup
func main() {
HandleFunc("/hello"...
package main
import . "fmt"
import . "net/http"
import "sync"
var servers sync.WaitGroup
func main() {
HandleFunc("/hello"...
package main
func Spawn(f ...func()) {
for _, s := range f {
servers.Add(1)
go func(server func()) {
defer servers.Done()
...
package main
func Spawn(f ...func()) {
for _, s := range f {
servers.Add(1)
go func(server func()) {
defer servers.Done()
...
tcp server
50go for the would-be network programmer http://slides.games-with-brains.net/
package main
import . "fmt"
import "net"
func main() {
if listener, e := net.Listen("tcp", ":1024"); e == nil {
for {
if c...
package main
import . "fmt"
import "net"
func main() {
if listener, e := net.Listen("tcp", ":1024"); e == nil {
for {
if c...
package main
import . "fmt"
import "net"
func main() {
if listener, e := net.Listen("tcp", ":1024"); e == nil {
for {
if c...
package main
import . "fmt"
import "net"
func main() {
if listener, e := net.Listen("tcp", ":1024"); e == nil {
for {
if c...
package main
import . "fmt"
import "net"
func main() {
if listener, e := net.Listen("tcp", ":1024"); e == nil {
for {
if c...
package main
import . "fmt"
import "net"
func main() {
Listen("tcp", ":1024", func(c net.Conn) {
defer c.Close()
Fprintln(...
package main
import . "fmt"
import "net"
func main() {
Listen("tcp", ":1024", func(c net.Conn) {
defer c.Close()
Fprintln(...
package main
import . "fmt"
import "net"
func main() {
Listen("tcp", ":1024", func(c net.Conn) {
defer c.Close()
Fprintln(...
package main
import . "fmt"
import "net"
func main() {
Listen("tcp", ":1024", func(c net.Conn) {
defer c.Close()
Fprintln(...
tcp client
60go for the would-be network programmer http://slides.games-with-brains.net/
package main
import "bufio"
import . "fmt"
import "net"
func main() {
if c, e := net.Dial("tcp", ":1024"); e == nil {
defe...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
if c, e := net.Dial("tcp", ":1024"); e == nil {
defe...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
if c, e := net.Dial("tcp", ":1024"); e == nil {
defe...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
if c, e := net.Dial("tcp", ":1024"); e == nil {
defe...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
if c, e := net.Dial("tcp", ":1024"); e == nil {
defe...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
if c, e := net.Dial("tcp", ":1024"); e == nil {
defe...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial("tcp", ":1024", func(c net.Conn) {
if m, e := b...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial("tcp", ":1024", func(c net.Conn) {
if m, e := b...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial("tcp", ":1024", func(c net.Conn) {
if m, e := b...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial("tcp", ":1024", func(c net.Conn) {
if m, e := b...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial("tcp", ":1024", func(c net.Conn) {
if m, e := b...
tcp/tls server
72go for the would-be network programmer http://slides.games-with-brains.net/
package main
import "crypto/tls"
import . "fmt"
func main() {
Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn...
package main
import "crypto/tls"
import . "fmt"
func main() {
Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn...
package main
import "crypto/tls"
import . "fmt"
func main() {
Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn...
package main
import "crypto/rand"
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.Load...
package main
import "crypto/rand"
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.Load...
package main
import "crypto/rand"
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.Load...
package main
import "crypto/rand"
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.Load...
package main
import "crypto/rand"
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.Load...
package main
import "crypto/tls"
func Listen(a string, conf *tls.Config, f func(*tls.Conn)) {
if listener, e := tls.Listen...
package main
import "crypto/tls"
func Listen(a string, conf *tls.Config, f func(*tls.Conn)) {
if listener, e := tls.Listen...
package main
import "crypto/tls"
func Listen(a string, conf *tls.Config, f func(*tls.Conn)) {
if listener, e := tls.Listen...
package main
import "crypto/tls"
func Listen(a string, conf *tls.Config, f func(*tls.Conn)) {
if listener, e := tls.Listen...
package main
import “crypto/tls"
import "net"
func Listen(a string, conf *tls.Config, f func(net.Conn)) {
if listener, e :...
package main
import "crypto/tls"
import "net"
func Listen(a string, conf *tls.Config, f func(net.Conn)) {
if listener, e :...
tcp/tls client
87go for the would-be network programmer http://slides.games-with-brains.net/
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1025", ConfigTLS("ccert", "ckey"), func(c net...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1025", ConfigTLS("ccert", "ckey"), func(c net...
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1025", ConfigTLS("ccert", "ckey"), func(c net...
package main
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.LoadX509KeyPair(c, k); e ...
package main
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.LoadX509KeyPair(c, k); e ...
package main
import "crypto/tls"
func ConfigTLS(c, k string) (r *tls.Config) {
if cert, e := tls.LoadX509KeyPair(c, k); e ...
package main
import “crypto/tls"
import "net"
func Dial(a string, conf *tls.Config, f func(net.Conn)) {
if c, e := tls.Dia...
package main
import “crypto/tls"
import "net"
func Dial(a string, conf *tls.Config, f func(net.Conn)) {
if c, e := tls.Dia...
udp serve
96go for the would-be network programmer http://slides.games-with-brains.net/
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn”)
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
package main
import "net"
func main() {
HELLO_WORLD := []byte("Hello Worldn")
Listen(":1024", func(c *net.UDPConn, a *net....
udp request
111go for the would-be network programmer http://slides.games-with-brains.net/
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
package main
import "bufio"
import . "fmt"
import "net"
func main() {
Dial(":1024", func(conn net.Conn) {
if _, e := conn....
aes encrypt
121go for the would-be network programmer http://slides.games-with-brains.net/
go for the would-be network programmer http://slides.games-with-brains.net/
122
package main
import "crypto/aes"
import "c...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
const AES_KEY = "012345678901234...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
const AES_KEY = "012345678901234...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
const AES_KEY = "012345678901234...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
const AES_KEY = "012345678901234...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Quantise(m string) (b []byt...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func IV() (b []byte, e error) {
...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func IV() (b []byte, e error) {
...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
package main
import "crypto/aes"
import "crypto/cipher"
import "crypto/rand"
import "net"
func Encrypt(m, k string) (o []b...
aes decrypt
147go for the would-be network programmer http://slides.games-with-brains.net/
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
const AES_KEY = "0123456789012345"
fun...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
const AES_KEY = "0123456789012345"
fun...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
const AES_KEY = "0123456789012345"
fun...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Decrypt(m []byte, k string) (r st...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Decrypt(m []byte, k string) (r st...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Decrypt(m []byte, k string) (r st...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Unpack(m []byte) (iv, r []byte) {...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Unpack(m []byte) (iv, r []byte) {...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Unpack(m []byte) (iv, r []byte) {...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Decrypt(m []byte, k string) (r st...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Decrypt(m []byte, k string) (r st...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Decrypt(m []byte, k string) (r st...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Dequantise(m []byte) string {
var...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Dequantise(m []byte) string {
var...
package main
import "crypto/cipher"
import "crypto/aes"
import . "fmt"
import "net"
func Dequantise(m []byte) string {
var...
rsa encrypt
163go for the would-be network programmer http://slides.games-with-brains.net/
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import . "bytes"
import "crypto/rsa"
import "encoding/gob"
import "net"
func main() {
HELLO_WORLD := []byte("...
package main
import "crypto/rand"
import "crypto/rsa"
import "crypto/sha1"
func Encrypt(key *rsa.PublicKey, m, l []byte) (...
package main
import "crypto/rand"
import "crypto/rsa"
import "crypto/sha1"
func Encrypt(key *rsa.PublicKey, m, l []byte) (...
package main
import "crypto/rand"
import "crypto/rsa"
import "crypto/sha1"
func Encrypt(key *rsa.PublicKey, m, l []byte) (...
package main
import "crypto/rand"
import "crypto/rsa"
import "crypto/sha1"
func Encrypt(key *rsa.PublicKey, m, l []byte) (...
package main
import "crypto/rand"
import "crypto/rsa"
import "crypto/sha1"
func Encrypt(key *rsa.PublicKey, m, l []byte) (...
rsa decrypt
178go for the would-be network programmer http://slides.games-with-brains.net/
package main
import "crypto/rsa"
import . "fmt"
import "net"
func main() {
Dial(":1025", "ckey", func(c *net.UDPConn, k *r...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func main() {
Dial(":1025", "ckey", func(c *net.UDPConn, k *r...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func main() {
Dial(":1025", "ckey", func(c *net.UDPConn, k *r...
package main
import "crypto/rand"
import "crypto/rsa"
import "crypto/sha1"
func Decrypt(key *rsa.PrivateKey, m, l []byte) ...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func main() {
Dial(":1025", "ckey", func(c *net.UDPConn, k *r...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func main() {
Dial(":1025", "ckey", func(c *net.UDPConn, k *r...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKe...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKe...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKe...
package main
import "crypto/rsa"
import "crypto/x509"
import "encoding/pem"
import "io/ioutil"
func LoadPrivateKey(file st...
package main
import "crypto/rsa"
import "crypto/x509"
import "encoding/pem"
import "io/ioutil"
func LoadPrivateKey(file st...
package main
import "crypto/rsa"
import "crypto/x509"
import "encoding/pem"
import "io/ioutil"
func LoadPrivateKey(file st...
package main
import "crypto/rsa"
import "crypto/x509"
import "encoding/pem"
import "io/ioutil"
func LoadPrivateKey(file st...
package main
import "crypto/rsa"
import "crypto/x509"
import "encoding/pem"
import "io/ioutil"
func LoadPrivateKey(file st...
package main
import "crypto/rsa"
import "crypto/x509"
import "encoding/pem"
import "io/ioutil"
func LoadPrivateKey(file st...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKe...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKe...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKe...
package main
import "bytes"
import “crypto/rsa"
import "encoding/gob"
import "net"
func SendKey(c *net.UDPConn, k rsa.Publ...
package main
import "bytes"
import “crypto/rsa"
import "encoding/gob"
import "net"
func SendKey(c *net.UDPConn, k rsa.Publ...
package main
import "bytes"
import “crypto/rsa"
import "encoding/gob"
import "net"
func SendKey(c *net.UDPConn, k rsa.Publ...
package main
import "crypto/rsa"
import . "fmt"
import "net"
func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKe...
http://golang.org/
go for the would-be network programmer http://slides.games-with-brains.net/201
twitter://#golang
go for the would-be network programmer http://slides.games-with-brains.net/202
Upcoming SlideShare
Loading in …5
×

Go for the paranoid network programmer

6,416 views

Published on

An enhanced version of the #codemesh2014 talk on network programming in Go. It covers HTTP, HTTPS, TCP/IP, TCP/IP over TLS, UDP and basic cryptographic functions with AES-CBC and RSA.

Published in: Software
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • .DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... .DOWNLOAD PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... .DOWNLOAD EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... .DOWNLOAD doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... .DOWNLOAD PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... .DOWNLOAD EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... .DOWNLOAD doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Go for the paranoid network programmer

  1. 1. go for the paranoid network programmer @feyeleanor 1go for the would-be network programmer http://slides.games-with-brains.net/
  2. 2. twitter://@feyeleanor go for the would-be network programmer http://slides.games-with-brains.net/
  3. 3. high voltage networking concurrency cryptography go for the would-be network programmer http://slides.games-with-brains.net/
  4. 4. http 4go for the would-be network programmer http://slides.games-with-brains.net/
  5. 5. package main import ( . "fmt" "net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { http.HandleFunc("/hello", Hello) if e := http.ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/5
  6. 6. package main import ( . "fmt" "net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { http.HandleFunc("/hello", Hello) if e := http.ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/6
  7. 7. package main import ( . "fmt" "net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { http.HandleFunc("/hello", Hello) if e := http.ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/7
  8. 8. package main import ( . "fmt" . "net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", Hello) if e := ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/8
  9. 9. package main import ( . "fmt" . ”net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", Hello) if e := ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/9
  10. 10. package main import ( . "fmt" . ”net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", Hello) if e := ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/10
  11. 11. package main import ( . "fmt" . ”net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", Hello) if e := ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/11
  12. 12. package main import ( . "fmt" . ”net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", Hello) if e := ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/12
  13. 13. package main import ( . "fmt" . ”net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", Hello) if e := ListenAndServe(ADDRESS, nil); e != nil { Println(e) } } func Hello(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) } go for the would-be network programmer http://slides.games-with-brains.net/13
  14. 14. package main import ( . "fmt" . "net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) }) ListenAndServe(ADDRESS, nil) } go for the would-be network programmer http://slides.games-with-brains.net/14
  15. 15. package main import ( . "fmt" . "net/http" ) const MESSAGE = "hello world" const ADDRESS = ":1024" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, MESSAGE) }) ListenAndServe(ADDRESS, nil) } go for the would-be network programmer http://slides.games-with-brains.net/15
  16. 16. https 16go for the would-be network programmer http://slides.games-with-brains.net/
  17. 17. package main import ( . "fmt" . "net/http" ) const ADDRESS = ":1025" func main() { message := "hello world" HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, message) }) ListenAndServeTLS(ADDRESS, "cert.pem", "key.pem", nil) } go for the would-be network programmer http://slides.games-with-brains.net/17
  18. 18. package main import ( . "fmt" . "net/http" ) const ADDRESS = ":1025" func main() { message := "hello world" HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, message) }) ListenAndServeTLS(ADDRESS, "cert.pem", "key.pem", nil) } go for the would-be network programmer http://slides.games-with-brains.net/18
  19. 19. package main import ( . "fmt" . "net/http" ) const ADDRESS = ":1025" func main() { message := "hello world" HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, message) }) ListenAndServeTLS(ADDRESS, "cert.pem", "key.pem", nil) } go for the would-be network programmer http://slides.games-with-brains.net/19
  20. 20. package main import ( . "fmt" . "net/http" ) const ADDRESS = ":1025" func main() { message := "hello world" HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, message) }) ListenAndServeTLS(ADDRESS, "cert.pem", "key.pem", nil) } go for the would-be network programmer http://slides.games-with-brains.net/20
  21. 21. multiple http servers 21go for the would-be network programmer http://slides.games-with-brains.net/
  22. 22. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/22
  23. 23. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/23
  24. 24. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/24
  25. 25. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/25
  26. 26. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/26
  27. 27. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/27
  28. 28. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/28
  29. 29. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/29
  30. 30. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) done := make(chan bool) go func() { ListenAndServe(":1024", nil) done <- true }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) <- done } go for the would-be network programmer http://slides.games-with-brains.net/30
  31. 31. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) Spawn( func() { ListenAndServe(":1024", nil) }, func() { ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }, ) } go for the would-be network programmer http://slides.games-with-brains.net/31
  32. 32. package main import . "fmt" import . "net/http" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) Spawn(func() { ListenAndServe(":1024", nil) }) Spawn(func() { ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }) } go for the would-be network programmer http://slides.games-with-brains.net/32
  33. 33. package main func Spawn(f ...func()) { done := make(chan bool) for _, s := range f { go func(server func()) { server() done <- true }(s) } for l := len(f); l > 0; l-- { <- done } } go for the would-be network programmer http://slides.games-with-brains.net/33
  34. 34. package main func Spawn(f ...func()) { done := make(chan bool) for _, s := range f { go func(server func()) { server() done <- true }(s) } for l := len(f); l > 0; l-- { <- done } } go for the would-be network programmer http://slides.games-with-brains.net/34
  35. 35. package main func Spawn(f ...func()) { done := make(chan bool) for _, s := range f { go func(server func()) { server() done <- true }(s) } for l := len(f); l > 0; l-- { <- done } } go for the would-be network programmer http://slides.games-with-brains.net/35
  36. 36. package main func Spawn(f ...func()) { done := make(chan bool) for _, s := range f { go func(server func()) { server() done <- true }(s) } for l := len(f); l > 0; l-- { <- done } } go for the would-be network programmer http://slides.games-with-brains.net/36
  37. 37. package main func Spawn(f ...func()) { done := make(chan bool) for _, s := range f { go func(server func()) { server() done <- true }(s) } for l := len(f); l > 0; l-- { <- done } } go for the would-be network programmer http://slides.games-with-brains.net/37
  38. 38. package main func Spawn(f ...func()) { done := make(chan bool) for _, s := range f { go func(server func()) { server() done <- true }(s) } for l := len(f); l > 0; l-- { <- done } } go for the would-be network programmer http://slides.games-with-brains.net/38
  39. 39. package main func Spawn(f ...func()) { done := make(chan bool) for _, s := range f { go func(server func()) { server() done <- true }(s) } for l := len(f); l > 0; l-- { <- done } } go for the would-be network programmer http://slides.games-with-brains.net/39
  40. 40. waitgroups 40go for the would-be network programmer http://slides.games-with-brains.net/
  41. 41. package main import . "fmt" import . "net/http" import "sync" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) {}) var servers sync.WaitGroup servers.Add(1) go func() { defer servers.Done() ListenAndServe(":1024", nil) }() servers.Add(1) go func() { defer servers.Done() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }() servers.Wait() } go for the would-be network programmer http://slides.games-with-brains.net/41
  42. 42. package main import . "fmt" import . "net/http" import "sync" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) {}) var servers sync.WaitGroup servers.Add(1) go func() { defer servers.Done() ListenAndServe(":1024", nil) }() servers.Add(1) go func() { defer servers.Done() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }() servers.Wait() } go for the would-be network programmer http://slides.games-with-brains.net/42
  43. 43. package main import . "fmt" import . "net/http" import "sync" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) {}) var servers sync.WaitGroup servers.Add(1) go func() { defer servers.Done() ListenAndServe(":1024", nil) }() servers.Add(1) go func() { defer servers.Done() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }() servers.Wait() } go for the would-be network programmer http://slides.games-with-brains.net/43
  44. 44. package main import . "fmt" import . "net/http" import "sync" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) {}) var servers sync.WaitGroup servers.Add(1) go func() { defer servers.Done() ListenAndServe(":1024", nil) }() servers.Add(1) go func() { defer servers.Done() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }() servers.Wait() } go for the would-be network programmer http://slides.games-with-brains.net/44
  45. 45. package main import . "fmt" import . "net/http" import "sync" func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) {}) var servers sync.WaitGroup servers.Add(1) go func() { defer servers.Done() ListenAndServe(":1024", nil) }() servers.Add(1) go func() { defer servers.Done() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }() servers.Wait() } go for the would-be network programmer http://slides.games-with-brains.net/45
  46. 46. package main import . "fmt" import . "net/http" import "sync" var servers sync.WaitGroup func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) Spawn(func() { ListenAndServe(":1024", nil) }) Spawn(func() { ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }) servers.Wait() } go for the would-be network programmer http://slides.games-with-brains.net/46
  47. 47. package main import . "fmt" import . "net/http" import "sync" var servers sync.WaitGroup func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) { w.Header().Set("Content-Type", "text/plain") Fprintf(w, "hello world") }) Spawn(func() { ListenAndServe(":1024", nil) }) Spawn(func() { ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil) }) servers.Wait() } go for the would-be network programmer http://slides.games-with-brains.net/47
  48. 48. package main func Spawn(f ...func()) { for _, s := range f { servers.Add(1) go func(server func()) { defer servers.Done() server() }(s) } } go for the would-be network programmer http://slides.games-with-brains.net/48
  49. 49. package main func Spawn(f ...func()) { for _, s := range f { servers.Add(1) go func(server func()) { defer servers.Done() server() }(s) } } go for the would-be network programmer http://slides.games-with-brains.net/49
  50. 50. tcp server 50go for the would-be network programmer http://slides.games-with-brains.net/
  51. 51. package main import . "fmt" import "net" func main() { if listener, e := net.Listen("tcp", ":1024"); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }(connection) } } } } go for the would-be network programmer http://slides.games-with-brains.net/51
  52. 52. package main import . "fmt" import "net" func main() { if listener, e := net.Listen("tcp", ":1024"); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }(connection) } } } } go for the would-be network programmer http://slides.games-with-brains.net/52
  53. 53. package main import . "fmt" import "net" func main() { if listener, e := net.Listen("tcp", ":1024"); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }(connection) } } } } go for the would-be network programmer http://slides.games-with-brains.net/53
  54. 54. package main import . "fmt" import "net" func main() { if listener, e := net.Listen("tcp", ":1024"); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }(connection) } } } } go for the would-be network programmer http://slides.games-with-brains.net/54
  55. 55. package main import . "fmt" import "net" func main() { if listener, e := net.Listen("tcp", ":1024"); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }(connection) } } } } go for the would-be network programmer http://slides.games-with-brains.net/55
  56. 56. package main import . "fmt" import "net" func main() { Listen("tcp", ":1024", func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }) } func Listen(p, a string, f func(net.Conn)) (e error) { var listener net.Listener if listener, e = net.Listen(p, a); e == nil { for { if connection, e := listener.Accept(); e == nil { go f(connection) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/56
  57. 57. package main import . "fmt" import "net" func main() { Listen("tcp", ":1024", func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }) } func Listen(p, a string, f func(net.Conn)) (e error) { var listener net.Listener if listener, e = net.Listen(p, a); e == nil { for { if connection, e := listener.Accept(); e == nil { go f(connection) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/57
  58. 58. package main import . "fmt" import "net" func main() { Listen("tcp", ":1024", func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }) } func Listen(p, a string, f func(net.Conn)) (e error) { var listener net.Listener if listener, e = net.Listen(p, a); e == nil { for { if connection, e := listener.Accept(); e == nil { go f(connection) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/58
  59. 59. package main import . "fmt" import "net" func main() { Listen("tcp", ":1024", func(c net.Conn) { defer c.Close() Fprintln(c, "hello world") }) } func Listen(p, a string, f func(net.Conn)) (e error) { var listener net.Listener if listener, e = net.Listen(p, a); e == nil { for { if connection, e := listener.Accept(); e == nil { go f(connection) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/59
  60. 60. tcp client 60go for the would-be network programmer http://slides.games-with-brains.net/
  61. 61. package main import "bufio" import . "fmt" import "net" func main() { if c, e := net.Dial("tcp", ":1024"); e == nil { defer c.Close() if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } } } go for the would-be network programmer http://slides.games-with-brains.net/61
  62. 62. package main import "bufio" import . "fmt" import "net" func main() { if c, e := net.Dial("tcp", ":1024"); e == nil { defer c.Close() if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } } } go for the would-be network programmer http://slides.games-with-brains.net/62
  63. 63. package main import "bufio" import . "fmt" import "net" func main() { if c, e := net.Dial("tcp", ":1024"); e == nil { defer c.Close() if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } } } go for the would-be network programmer http://slides.games-with-brains.net/63
  64. 64. package main import "bufio" import . "fmt" import "net" func main() { if c, e := net.Dial("tcp", ":1024"); e == nil { defer c.Close() if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } } } go for the would-be network programmer http://slides.games-with-brains.net/64
  65. 65. package main import "bufio" import . "fmt" import "net" func main() { if c, e := net.Dial("tcp", ":1024"); e == nil { defer c.Close() if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } } } go for the would-be network programmer http://slides.games-with-brains.net/65
  66. 66. package main import "bufio" import . "fmt" import "net" func main() { if c, e := net.Dial("tcp", ":1024"); e == nil { defer c.Close() if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } } } go for the would-be network programmer http://slides.games-with-brains.net/66
  67. 67. package main import "bufio" import . "fmt" import "net" func main() { Dial("tcp", ":1024", func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } go for the would-be network programmer http://slides.games-with-brains.net/67
  68. 68. package main import "bufio" import . "fmt" import "net" func main() { Dial("tcp", ":1024", func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } func Dial(p, a string, f func(net.Conn)) (e error) { var c net.Conn if c, e = net.Dial(p, a); e == nil { defer c.Close() f(c) } return } go for the would-be network programmer http://slides.games-with-brains.net/68
  69. 69. package main import "bufio" import . "fmt" import "net" func main() { Dial("tcp", ":1024", func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } func Dial(p, a string, f func(net.Conn)) (e error) { var c net.Conn if c, e = net.Dial(p, a); e == nil { defer c.Close() f(c) } return } go for the would-be network programmer http://slides.games-with-brains.net/69
  70. 70. package main import "bufio" import . "fmt" import "net" func main() { Dial("tcp", ":1024", func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } func Dial(p, a string, f func(net.Conn)) (e error) { var c net.Conn if c, e = net.Dial(p, a); e == nil { defer c.Close() f(c) } return } go for the would-be network programmer http://slides.games-with-brains.net/70
  71. 71. package main import "bufio" import . "fmt" import "net" func main() { Dial("tcp", ":1024", func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } func Dial(p, a string, f func(net.Conn)) (e error) { var c net.Conn if c, e = net.Dial(p, a); e == nil { defer c.Close() f(c) } return } go for the would-be network programmer http://slides.games-with-brains.net/71
  72. 72. tcp/tls server 72go for the would-be network programmer http://slides.games-with-brains.net/
  73. 73. package main import "crypto/tls" import . "fmt" func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world") }) } go for the would-be network programmer http://slides.games-with-brains.net/73
  74. 74. package main import "crypto/tls" import . "fmt" func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world") }) } go for the would-be network programmer http://slides.games-with-brains.net/74
  75. 75. package main import "crypto/tls" import . "fmt" func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world") }) } go for the would-be network programmer http://slides.games-with-brains.net/75
  76. 76. package main import "crypto/rand" import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, Rand: rand.Reader, } } return } go for the would-be network programmer http://slides.games-with-brains.net/76
  77. 77. package main import "crypto/rand" import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, Rand: rand.Reader, } } return } go for the would-be network programmer http://slides.games-with-brains.net/77
  78. 78. package main import "crypto/rand" import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, Rand: rand.Reader, } } return } go for the would-be network programmer http://slides.games-with-brains.net/78
  79. 79. package main import "crypto/rand" import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, Rand: rand.Reader, } } return } go for the would-be network programmer http://slides.games-with-brains.net/79
  80. 80. package main import "crypto/rand" import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, Rand: rand.Reader, } } return } go for the would-be network programmer http://slides.games-with-brains.net/80
  81. 81. package main import "crypto/tls" func Listen(a string, conf *tls.Config, f func(*tls.Conn)) { if listener, e := tls.Listen("tcp", a, conf); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c *tls.Conn) { defer c.Close() f(c) }(connection.(*tls.Conn)) } } } } go for the would-be network programmer http://slides.games-with-brains.net/81
  82. 82. package main import "crypto/tls" func Listen(a string, conf *tls.Config, f func(*tls.Conn)) { if listener, e := tls.Listen("tcp", a, conf); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c *tls.Conn) { defer c.Close() f(c) }(connection.(*tls.Conn)) } } } } go for the would-be network programmer http://slides.games-with-brains.net/82
  83. 83. package main import "crypto/tls" func Listen(a string, conf *tls.Config, f func(*tls.Conn)) { if listener, e := tls.Listen("tcp", a, conf); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c *tls.Conn) { defer c.Close() f(c) }(connection.(*tls.Conn)) } } } } go for the would-be network programmer http://slides.games-with-brains.net/83
  84. 84. package main import "crypto/tls" func Listen(a string, conf *tls.Config, f func(*tls.Conn)) { if listener, e := tls.Listen("tcp", a, conf); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c *tls.Conn) { defer c.Close() f(c) }(connection.(*tls.Conn)) } } } } go for the would-be network programmer http://slides.games-with-brains.net/84
  85. 85. package main import “crypto/tls" import "net" func Listen(a string, conf *tls.Config, f func(net.Conn)) { if listener, e := tls.Listen("tcp", a, conf); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c net.Conn) { defer c.Close() f(c) }(connection) } } } } go for the would-be network programmer http://slides.games-with-brains.net/85
  86. 86. package main import "crypto/tls" import "net" func Listen(a string, conf *tls.Config, f func(net.Conn)) { if listener, e := tls.Listen("tcp", a, conf); e == nil { for { if connection, e := listener.Accept(); e == nil { go func(c net.Conn) { defer c.Close() f(c) }(connection) } } } } go for the would-be network programmer http://slides.games-with-brains.net/86
  87. 87. tcp/tls client 87go for the would-be network programmer http://slides.games-with-brains.net/
  88. 88. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1025", ConfigTLS("ccert", "ckey"), func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } go for the would-be network programmer http://slides.games-with-brains.net/88
  89. 89. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1025", ConfigTLS("ccert", "ckey"), func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } go for the would-be network programmer http://slides.games-with-brains.net/89
  90. 90. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1025", ConfigTLS("ccert", "ckey"), func(c net.Conn) { if m, e := bufio.NewReader(c).ReadString('n'); e == nil { Printf(m) } }) } go for the would-be network programmer http://slides.games-with-brains.net/90
  91. 91. package main import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, InsecureSkipVerify: true, } } return } go for the would-be network programmer http://slides.games-with-brains.net/91
  92. 92. package main import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, InsecureSkipVerify: true, } } return } go for the would-be network programmer http://slides.games-with-brains.net/92
  93. 93. package main import "crypto/tls" func ConfigTLS(c, k string) (r *tls.Config) { if cert, e := tls.LoadX509KeyPair(c, k); e == nil { r = &tls.Config{ Certificates: []tls.Certificate{ cert }, InsecureSkipVerify: true, } } return } go for the would-be network programmer http://slides.games-with-brains.net/93
  94. 94. package main import “crypto/tls" import "net" func Dial(a string, conf *tls.Config, f func(net.Conn)) { if c, e := tls.Dial("tcp", a, conf); e == nil { defer c.Close() f(c) } } go for the would-be network programmer http://slides.games-with-brains.net/94
  95. 95. package main import “crypto/tls" import "net" func Dial(a string, conf *tls.Config, f func(net.Conn)) { if c, e := tls.Dial("tcp", a, conf); e == nil { defer c.Close() f(c) } } go for the would-be network programmer http://slides.games-with-brains.net/95
  96. 96. udp serve 96go for the would-be network programmer http://slides.games-with-brains.net/
  97. 97. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/97
  98. 98. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn”) Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/98
  99. 99. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/99
  100. 100. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/100
  101. 101. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/101
  102. 102. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/102
  103. 103. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/103
  104. 104. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/104
  105. 105. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/105
  106. 106. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/106
  107. 107. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/107
  108. 108. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/108
  109. 109. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/109
  110. 110. package main import "net" func main() { HELLO_WORLD := []byte("Hello Worldn") Listen(":1024", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { c.WriteToUDP(HELLO_WORLD, a) }) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.ListenUDP("udp", address); e == nil { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := conn.ReadFromUDP(b); e == nil { go f(conn, client, b[:n]) } } } } return } go for the would-be network programmer http://slides.games-with-brains.net/110
  111. 111. udp request 111go for the would-be network programmer http://slides.games-with-brains.net/
  112. 112. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/112
  113. 113. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/113
  114. 114. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/114
  115. 115. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/115
  116. 116. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/116
  117. 117. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/117
  118. 118. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/118
  119. 119. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/119
  120. 120. package main import "bufio" import . "fmt" import "net" func main() { Dial(":1024", func(conn net.Conn) { if _, e := conn.Write([]byte("n")); e == nil { if m, e := bufio.NewReader(conn).ReadString('n'); e == nil { Printf("%v", m) } } }) } func Dial(a string, f func(net.Conn)) { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() f(conn) } } } go for the would-be network programmer http://slides.games-with-brains.net/120
  121. 121. aes encrypt 121go for the would-be network programmer http://slides.games-with-brains.net/
  122. 122. go for the would-be network programmer http://slides.games-with-brains.net/ 122 package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" const AES_KEY = "0123456789012345" func main() { Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { if m, e := Encrypt("Hello World", AES_KEY); e == nil { c.WriteToUDP(m, a) } }) }
  123. 123. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" const AES_KEY = "0123456789012345" func main() { Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { if m, e := Encrypt("Hello World", AES_KEY); e == nil { c.WriteToUDP(m, a) } return }) } go for the would-be network programmer http://slides.games-with-brains.net/123
  124. 124. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" const AES_KEY = "0123456789012345" func main() { Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { if m, e := Encrypt("Hello World", AES_KEY); e == nil { c.WriteToUDP(m, a) } return }) } go for the would-be network programmer http://slides.games-with-brains.net/124
  125. 125. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" const AES_KEY = "0123456789012345" func main() { Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { if m, e := Encrypt("Hello World", AES_KEY); e == nil { c.WriteToUDP(m, a) } return }) } go for the would-be network programmer http://slides.games-with-brains.net/125
  126. 126. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" const AES_KEY = "0123456789012345" func main() { Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { if m, e := Encrypt("Hello World", AES_KEY); e == nil { c.WriteToUDP(m, a) } return }) } go for the would-be network programmer http://slides.games-with-brains.net/126
  127. 127. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise([]byte(m)); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/127
  128. 128. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise([]byte(m)); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/128
  129. 129. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/129
  130. 130. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/130
  131. 131. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/131
  132. 132. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/132
  133. 133. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/133
  134. 134. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/134
  135. 135. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/135
  136. 136. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/136
  137. 137. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Quantise(m string) (b []byte, e error) { b = append(b, m...) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p // this is insecure and inflexible as we're padding with NUL! b = append(b, make([]byte, p)...) } return } go for the would-be network programmer http://slides.games-with-brains.net/137
  138. 138. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/138
  139. 139. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/139
  140. 140. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/140
  141. 141. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/141
  142. 142. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func IV() (b []byte, e error) { b = make([]byte, aes.BlockSize) _, e = rand.Read(b) return } go for the would-be network programmer http://slides.games-with-brains.net/142
  143. 143. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func IV() (b []byte, e error) { b = make([]byte, aes.BlockSize) _, e = rand.Read(b) return } go for the would-be network programmer http://slides.games-with-brains.net/143
  144. 144. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/144
  145. 145. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/145
  146. 146. package main import "crypto/aes" import "crypto/cipher" import "crypto/rand" import "net" func Encrypt(m, k string) (o []byte, e error) { if o, e = Quantise(m); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte if iv, e = IV(); e == nil { c := cipher.NewCBCEncrypter(b, iv) c.CryptBlocks(o, o) o = append(iv, o...) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/146
  147. 147. aes decrypt 147go for the would-be network programmer http://slides.games-with-brains.net/
  148. 148. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" const AES_KEY = "0123456789012345" func main() { Dial(":1025", func(c *net.UDPConn) { c.Write(make([]byte, 1)) if m, e := ReadStream(c); e == nil { if m, e := Decrypt(m, AES_KEY); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/148
  149. 149. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" const AES_KEY = "0123456789012345" func main() { Dial(":1025", func(c *net.UDPConn) { c.Write(make([]byte, 1)) if m, e := ReadStream(c); e == nil { if m, e := Decrypt(m, AES_KEY); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/149
  150. 150. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" const AES_KEY = "0123456789012345" func main() { Dial(":1025", func(c *net.UDPConn) { c.Write(make([]byte, 1)) if m, e := ReadStream(c); e == nil { if m, e := Decrypt(m, AES_KEY); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/150
  151. 151. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Decrypt(m []byte, k string) (r string, e error) { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte iv, m = Unpack(m) c := cipher.NewCBCDecrypter(b, iv) c.CryptBlocks(m, m) r = Dequantise(m) } return } go for the would-be network programmer http://slides.games-with-brains.net/151
  152. 152. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Decrypt(m []byte, k string) (r string, e error) { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte iv, m = Unpack(m) c := cipher.NewCBCDecrypter(b, iv) c.CryptBlocks(m, m) r = Dequantise(m) } return } go for the would-be network programmer http://slides.games-with-brains.net/152
  153. 153. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Decrypt(m []byte, k string) (r string, e error) { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte iv, m = Unpack(m) c := cipher.NewCBCDecrypter(b, iv) c.CryptBlocks(m, m) r = Dequantise(m) } return } go for the would-be network programmer http://slides.games-with-brains.net/153
  154. 154. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize:] } go for the would-be network programmer http://slides.games-with-brains.net/154
  155. 155. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize:] } go for the would-be network programmer http://slides.games-with-brains.net/155
  156. 156. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize:] } go for the would-be network programmer http://slides.games-with-brains.net/156
  157. 157. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Decrypt(m []byte, k string) (r string, e error) { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte iv, m = Unpack(m) c := cipher.NewCBCDecrypter(b, iv) c.CryptBlocks(m, m) r = Dequantise(m) } return } go for the would-be network programmer http://slides.games-with-brains.net/157
  158. 158. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Decrypt(m []byte, k string) (r string, e error) { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte iv, m = Unpack(m) c := cipher.NewCBCDecrypter(b, iv) c.CryptBlocks(m, m) r = Dequantise(m) } return } go for the would-be network programmer http://slides.games-with-brains.net/158
  159. 159. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Decrypt(m []byte, k string) (r string, e error) { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byte iv, m = Unpack(m) c := cipher.NewCBCDecrypter(b, iv) c.CryptBlocks(m, m) r = Dequantise(m) } return } go for the would-be network programmer http://slides.games-with-brains.net/159
  160. 160. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Dequantise(m []byte) string { var i int for i = len(m) - 1; i > 0 && m[i] == 0; i-- {} return string(m[:i + 1]) } go for the would-be network programmer http://slides.games-with-brains.net/160
  161. 161. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Dequantise(m []byte) string { var i int for i = len(m) - 1; i > 0 && m[i] == 0; i-- {} return string(m[:i + 1]) } go for the would-be network programmer http://slides.games-with-brains.net/161
  162. 162. package main import "crypto/cipher" import "crypto/aes" import . "fmt" import "net" func Dequantise(m []byte) string { var i int for i = len(m) - 1; i > 0 && m[i] == 0; i-- {} return string(m[:i + 1]) } go for the would-be network programmer http://slides.games-with-brains.net/162
  163. 163. rsa encrypt 163go for the would-be network programmer http://slides.games-with-brains.net/
  164. 164. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/164
  165. 165. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/165
  166. 166. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/166
  167. 167. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/167
  168. 168. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/168
  169. 169. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/169
  170. 170. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/170
  171. 171. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/171
  172. 172. package main import . "bytes" import "crypto/rsa" import "encoding/gob" import "net" func main() { HELLO_WORLD := []byte("Hello World") RSA_LABEL := []byte("served") Listen(":1025", func(c *net.UDPConn, a *net.UDPAddr, b []byte) { var key rsa.PublicKey if e := gob.NewDecoder(NewBuffer(b)).Decode(&key); e == nil { if m, e := Encrypt(&key, HELLO_WORLD, RSA_LABEL); e == nil { c.WriteToUDP(m, a) } } return }) } go for the would-be network programmer http://slides.games-with-brains.net/172
  173. 173. package main import "crypto/rand" import "crypto/rsa" import "crypto/sha1" func Encrypt(key *rsa.PublicKey, m, l []byte) ([]byte, error) { return rsa.EncryptOAEP(sha1.New(), rand.Reader, key, m, l) } go for the would-be network programmer http://slides.games-with-brains.net/173
  174. 174. package main import "crypto/rand" import "crypto/rsa" import "crypto/sha1" func Encrypt(key *rsa.PublicKey, m, l []byte) ([]byte, error) { return rsa.EncryptOAEP(sha1.New(), rand.Reader, key, m, l) } go for the would-be network programmer http://slides.games-with-brains.net/174
  175. 175. package main import "crypto/rand" import "crypto/rsa" import "crypto/sha1" func Encrypt(key *rsa.PublicKey, m, l []byte) ([]byte, error) { return rsa.EncryptOAEP(sha1.New(), rand.Reader, key, m, l) } go for the would-be network programmer http://slides.games-with-brains.net/175
  176. 176. package main import "crypto/rand" import "crypto/rsa" import "crypto/sha1" func Encrypt(key *rsa.PublicKey, m, l []byte) ([]byte, error) { return rsa.EncryptOAEP(sha1.New(), rand.Reader, key, m, l) } go for the would-be network programmer http://slides.games-with-brains.net/176
  177. 177. package main import "crypto/rand" import "crypto/rsa" import "crypto/sha1" func Encrypt(key *rsa.PublicKey, m, l []byte) ([]byte, error) { return rsa.EncryptOAEP(sha1.New(), rand.Reader, key, m, l) } go for the would-be network programmer http://slides.games-with-brains.net/177
  178. 178. rsa decrypt 178go for the would-be network programmer http://slides.games-with-brains.net/
  179. 179. package main import "crypto/rsa" import . "fmt" import "net" func main() { Dial(":1025", "ckey", func(c *net.UDPConn, k *rsa.PrivateKey) { if m, e := ReadStream(c); e == nil { if m, e := Decrypt(k, m, []byte("served")); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/179
  180. 180. package main import "crypto/rsa" import . "fmt" import "net" func main() { Dial(":1025", "ckey", func(c *net.UDPConn, k *rsa.PrivateKey) { if m, e := ReadStream(c); e == nil { if m, e := Decrypt(k, m, []byte("served")); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/180
  181. 181. package main import "crypto/rsa" import . "fmt" import "net" func main() { Dial(":1025", "ckey", func(c *net.UDPConn, k *rsa.PrivateKey) { if m, e := ReadStream(c); e == nil { if m, e := Decrypt(k, m, []byte("served")); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/181
  182. 182. package main import "crypto/rand" import "crypto/rsa" import "crypto/sha1" func Decrypt(key *rsa.PrivateKey, m, l []byte) ([]byte, error) { return rsa.DecryptOAEP(sha1.New(), rand.Reader, key, m, l) } go for the would-be network programmer http://slides.games-with-brains.net/182
  183. 183. package main import "crypto/rsa" import . "fmt" import "net" func main() { Dial(":1025", "ckey", func(c *net.UDPConn, k *rsa.PrivateKey) { if m, e := ReadStream(c); e == nil { if m, e := Decrypt(k, m, []byte("served")); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/183
  184. 184. package main import "crypto/rsa" import . "fmt" import "net" func main() { Dial(":1025", "ckey", func(c *net.UDPConn, k *rsa.PrivateKey) { if m, e := ReadStream(c); e == nil { if m, e := Decrypt(k, m, []byte("served")); e == nil { Println(string(m)) } } }) } go for the would-be network programmer http://slides.games-with-brains.net/184
  185. 185. package main import "crypto/rsa" import . "fmt" import "net" func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKey)) { if k, e := LoadPrivateKey(file); e == nil { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() SendKey(conn, k.PublicKey, func() { f(conn, k) }) } } } } go for the would-be network programmer http://slides.games-with-brains.net/185
  186. 186. package main import "crypto/rsa" import . "fmt" import "net" func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKey)) { if k, e := LoadPrivateKey(file); e == nil { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() SendKey(conn, k.PublicKey, func() { f(conn, k) }) } } } } go for the would-be network programmer http://slides.games-with-brains.net/186
  187. 187. package main import "crypto/rsa" import . "fmt" import "net" func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKey)) { if k, e := LoadPrivateKey(file); e == nil { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() SendKey(conn, k.PublicKey, func() { f(conn, k) }) } } } } go for the would-be network programmer http://slides.games-with-brains.net/187
  188. 188. package main import "crypto/rsa" import "crypto/x509" import "encoding/pem" import "io/ioutil" func LoadPrivateKey(file string) (r *rsa.PrivateKey, e error) { if file, e := ioutil.ReadFile(file); e == nil { if block, _ := pem.Decode(file); block != nil { if block.Type == "RSA PRIVATE KEY" { r, e = x509.ParsePKCS1PrivateKey(block.Bytes) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/188
  189. 189. package main import "crypto/rsa" import "crypto/x509" import "encoding/pem" import "io/ioutil" func LoadPrivateKey(file string) (r *rsa.PrivateKey, e error) { if file, e := ioutil.ReadFile(file); e == nil { if block, _ := pem.Decode(file); block != nil { if block.Type == "RSA PRIVATE KEY" { r, e = x509.ParsePKCS1PrivateKey(block.Bytes) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/189
  190. 190. package main import "crypto/rsa" import "crypto/x509" import "encoding/pem" import "io/ioutil" func LoadPrivateKey(file string) (r *rsa.PrivateKey, e error) { if file, e := ioutil.ReadFile(file); e == nil { if block, _ := pem.Decode(file); block != nil { if block.Type == "RSA PRIVATE KEY" { r, e = x509.ParsePKCS1PrivateKey(block.Bytes) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/190
  191. 191. package main import "crypto/rsa" import "crypto/x509" import "encoding/pem" import "io/ioutil" func LoadPrivateKey(file string) (r *rsa.PrivateKey, e error) { if file, e := ioutil.ReadFile(file); e == nil { if block, _ := pem.Decode(file); block != nil { if block.Type == "RSA PRIVATE KEY" { r, e = x509.ParsePKCS1PrivateKey(block.Bytes) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/191
  192. 192. package main import "crypto/rsa" import "crypto/x509" import "encoding/pem" import "io/ioutil" func LoadPrivateKey(file string) (r *rsa.PrivateKey, e error) { if file, e := ioutil.ReadFile(file); e == nil { if block, _ := pem.Decode(file); block != nil { if block.Type == "RSA PRIVATE KEY" { r, e = x509.ParsePKCS1PrivateKey(block.Bytes) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/192
  193. 193. package main import "crypto/rsa" import "crypto/x509" import "encoding/pem" import "io/ioutil" func LoadPrivateKey(file string) (r *rsa.PrivateKey, e error) { if file, e := ioutil.ReadFile(file); e == nil { if block, _ := pem.Decode(file); block != nil { if block.Type == "RSA PRIVATE KEY" { r, e = x509.ParsePKCS1PrivateKey(block.Bytes) } } } return } go for the would-be network programmer http://slides.games-with-brains.net/193
  194. 194. package main import "crypto/rsa" import . "fmt" import "net" func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKey)) { if k, e := LoadPrivateKey(file); e == nil { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() SendKey(conn, k.PublicKey, func() { f(conn, k) }) } } } } go for the would-be network programmer http://slides.games-with-brains.net/194
  195. 195. package main import "crypto/rsa" import . "fmt" import "net" func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKey)) { if k, e := LoadPrivateKey(file); e == nil { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() SendKey(conn, k.PublicKey, func() { f(conn, k) }) } } } } go for the would-be network programmer http://slides.games-with-brains.net/195
  196. 196. package main import "crypto/rsa" import . "fmt" import "net" func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKey)) { if k, e := LoadPrivateKey(file); e == nil { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() SendKey(conn, k.PublicKey, func() { f(conn, k) }) } } } } go for the would-be network programmer http://slides.games-with-brains.net/196
  197. 197. package main import "bytes" import “crypto/rsa" import "encoding/gob" import "net" func SendKey(c *net.UDPConn, k rsa.PublicKey, f func()) { var b bytes.Buffer if e := gob.NewEncoder(&b).Encode(k); e == nil { if _, e = c.Write(b.Bytes()); e == nil { f() } } } go for the would-be network programmer http://slides.games-with-brains.net/197
  198. 198. package main import "bytes" import “crypto/rsa" import "encoding/gob" import "net" func SendKey(c *net.UDPConn, k rsa.PublicKey, f func()) { var b bytes.Buffer if e := gob.NewEncoder(&b).Encode(k); e == nil { if _, e = c.Write(b.Bytes()); e == nil { f() } } } go for the would-be network programmer http://slides.games-with-brains.net/198
  199. 199. package main import "bytes" import “crypto/rsa" import "encoding/gob" import "net" func SendKey(c *net.UDPConn, k rsa.PublicKey, f func()) { var b bytes.Buffer if e := gob.NewEncoder(&b).Encode(k); e == nil { if _, e = c.Write(b.Bytes()); e == nil { f() } } } go for the would-be network programmer http://slides.games-with-brains.net/199
  200. 200. package main import "crypto/rsa" import . "fmt" import "net" func Dial(a, file string, f func(*net.UDPConn, *rsa.PrivateKey)) { if k, e := LoadPrivateKey(file); e == nil { if address, e := net.ResolveUDPAddr("udp", a); e == nil { if conn, e := net.DialUDP("udp", nil, address); e == nil { defer conn.Close() SendKey(conn, k.PublicKey, func() { f(conn, k) }) } } } } go for the would-be network programmer http://slides.games-with-brains.net/200
  201. 201. http://golang.org/ go for the would-be network programmer http://slides.games-with-brains.net/201
  202. 202. twitter://#golang go for the would-be network programmer http://slides.games-with-brains.net/202

×