SlideShare une entreprise Scribd logo
1  sur  202
Télécharger pour lire hors ligne
go
for the paranoid network programmer
@feyeleanor
1go for the would-be network programmer http://slides.games-with-brains.net/
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.net/
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.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
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
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
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
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
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
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
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
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
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
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
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("/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
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
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
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
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.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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 *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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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
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
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
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
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 {
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
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
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
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
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
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
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
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
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
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
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
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) {
Fprintln(c, "hello world")
})
}
go for the would-be network programmer http://slides.games-with-brains.net/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/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/75
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
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
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
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
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
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
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
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
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
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
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
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.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
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
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
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
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
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
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
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
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.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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.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
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
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
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
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
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
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
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
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
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 "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)
}
})
}
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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"
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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("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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 *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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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

Contenu connexe

Tendances

Go for the paranoid network programmer, 2nd edition
Go for the paranoid network programmer, 2nd editionGo for the paranoid network programmer, 2nd edition
Go for the paranoid network programmer, 2nd editionEleanor McHugh
 
Going Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with GoGoing Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with GoEleanor McHugh
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programmingAnung Ariwibowo
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionIan Barber
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQAFest
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyVMware Tanzu
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureAmaury Bouchard
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
Distributed Data Structures
Distributed Data StructuresDistributed Data Structures
Distributed Data StructuresPDX Web & Design
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)CODE BLUE
 
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014Fantix King 王川
 
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Elixir Club
 

Tendances (20)

Go for the paranoid network programmer, 2nd edition
Go for the paranoid network programmer, 2nd editionGo for the paranoid network programmer, 2nd edition
Go for the paranoid network programmer, 2nd edition
 
Going Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with GoGoing Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with Go
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
Usp
UspUsp
Usp
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Rust
RustRust
Rust
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
 
Binomial heap
Binomial heapBinomial heap
Binomial heap
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
 
FPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixirFPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixir
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heure
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
 
Distributed Data Structures
Distributed Data StructuresDistributed Data Structures
Distributed Data Structures
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
 
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
 
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
 

Similaire à Go for the paranoid network programmer

Go for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd editionGo for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd editionEleanor McHugh
 
Iss letcure 7_8
Iss letcure 7_8Iss letcure 7_8
Iss letcure 7_8Ali Habeeb
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Ismael Celis
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
Remote Notifications
Remote NotificationsRemote Notifications
Remote NotificationsJosef Cacek
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with goHean Hong Leong
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Samuel Lampa
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioRick Copeland
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaFrank Lyaruu
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqelajobandesther
 
FlashAir Android App Development
FlashAir Android App DevelopmentFlashAir Android App Development
FlashAir Android App DevelopmentFlashAir Developers
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web developmentJohannes Brodwall
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
The Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveThe Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveEleanor McHugh
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4DEVCON
 

Similaire à Go for the paranoid network programmer (20)

Go for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd editionGo for the paranoid network programmer, 3rd edition
Go for the paranoid network programmer, 3rd edition
 
Iss letcure 7_8
Iss letcure 7_8Iss letcure 7_8
Iss letcure 7_8
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
 
Hello Go
Hello GoHello Go
Hello Go
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
Remote Notifications
Remote NotificationsRemote Notifications
Remote Notifications
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with go
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Introduction to asyncio
Introduction to asyncioIntroduction to asyncio
Introduction to asyncio
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 
FlashAir Android App Development
FlashAir Android App DevelopmentFlashAir Android App Development
FlashAir Android App Development
 
goatwork2014
goatwork2014goatwork2014
goatwork2014
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
The Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveThe Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's Perspective
 
About Node.js
About Node.jsAbout Node.js
About Node.js
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
 

Plus de Eleanor McHugh

[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdfEleanor McHugh
 
Generics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient CollectionsGenerics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient CollectionsEleanor McHugh
 
The Relevance of Liveness - Biometrics and Data Integrity
The Relevance of Liveness - Biometrics and Data IntegrityThe Relevance of Liveness - Biometrics and Data Integrity
The Relevance of Liveness - Biometrics and Data IntegrityEleanor McHugh
 
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]Eleanor McHugh
 
An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]Eleanor McHugh
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with goEleanor McHugh
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxEleanor McHugh
 
Identity & trust in Monitored Spaces
Identity & trust in Monitored SpacesIdentity & trust in Monitored Spaces
Identity & trust in Monitored SpacesEleanor McHugh
 
Don't Ask, Don't Tell - The Virtues of Privacy By Design
Don't Ask, Don't Tell - The Virtues of Privacy By DesignDon't Ask, Don't Tell - The Virtues of Privacy By Design
Don't Ask, Don't Tell - The Virtues of Privacy By DesignEleanor McHugh
 
Don't ask, don't tell the virtues of privacy by design
Don't ask, don't tell   the virtues of privacy by designDon't ask, don't tell   the virtues of privacy by design
Don't ask, don't tell the virtues of privacy by designEleanor McHugh
 
Anonymity, identity, trust
Anonymity, identity, trustAnonymity, identity, trust
Anonymity, identity, trustEleanor McHugh
 
Going Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google GoGoing Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google GoEleanor McHugh
 
Distributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at ScaleDistributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at ScaleEleanor McHugh
 
Finding a useful outlet for my many Adventures in go
Finding a useful outlet for my many Adventures in goFinding a useful outlet for my many Adventures in go
Finding a useful outlet for my many Adventures in goEleanor McHugh
 
Anonymity, trust, accountability
Anonymity, trust, accountabilityAnonymity, trust, accountability
Anonymity, trust, accountabilityEleanor McHugh
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CEleanor McHugh
 
Implementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CImplementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CEleanor McHugh
 
Privacy is always a requirement
Privacy is always a requirementPrivacy is always a requirement
Privacy is always a requirementEleanor McHugh
 
Hybrid Cryptography with examples in Ruby and Go
Hybrid Cryptography with examples in Ruby and GoHybrid Cryptography with examples in Ruby and Go
Hybrid Cryptography with examples in Ruby and GoEleanor McHugh
 

Plus de Eleanor McHugh (20)

[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
 
Generics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient CollectionsGenerics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient Collections
 
The Relevance of Liveness - Biometrics and Data Integrity
The Relevance of Liveness - Biometrics and Data IntegrityThe Relevance of Liveness - Biometrics and Data Integrity
The Relevance of Liveness - Biometrics and Data Integrity
 
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
 
An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with go
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
Identity & trust in Monitored Spaces
Identity & trust in Monitored SpacesIdentity & trust in Monitored Spaces
Identity & trust in Monitored Spaces
 
Don't Ask, Don't Tell - The Virtues of Privacy By Design
Don't Ask, Don't Tell - The Virtues of Privacy By DesignDon't Ask, Don't Tell - The Virtues of Privacy By Design
Don't Ask, Don't Tell - The Virtues of Privacy By Design
 
Don't ask, don't tell the virtues of privacy by design
Don't ask, don't tell   the virtues of privacy by designDon't ask, don't tell   the virtues of privacy by design
Don't ask, don't tell the virtues of privacy by design
 
Anonymity, identity, trust
Anonymity, identity, trustAnonymity, identity, trust
Anonymity, identity, trust
 
Going Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google GoGoing Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google Go
 
Distributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at ScaleDistributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at Scale
 
Finding a useful outlet for my many Adventures in go
Finding a useful outlet for my many Adventures in goFinding a useful outlet for my many Adventures in go
Finding a useful outlet for my many Adventures in go
 
Anonymity, trust, accountability
Anonymity, trust, accountabilityAnonymity, trust, accountability
Anonymity, trust, accountability
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & C
 
Implementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CImplementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & C
 
Privacy is always a requirement
Privacy is always a requirementPrivacy is always a requirement
Privacy is always a requirement
 
Hybrid Cryptography with examples in Ruby and Go
Hybrid Cryptography with examples in Ruby and GoHybrid Cryptography with examples in Ruby and Go
Hybrid Cryptography with examples in Ruby and Go
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 

Dernier

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 

Dernier (20)

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 

Go for the paranoid network programmer

  • 1. go for the paranoid network programmer @feyeleanor 1go for the would-be network programmer http://slides.games-with-brains.net/
  • 2. twitter://@feyeleanor go for the would-be network programmer http://slides.games-with-brains.net/
  • 3. high voltage networking concurrency cryptography go for the would-be network programmer http://slides.games-with-brains.net/
  • 4. http 4go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. https 16go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. multiple http servers 21go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. waitgroups 40go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. tcp server 50go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. tcp client 60go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. tcp/tls server 72go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. tcp/tls client 87go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. udp serve 96go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. udp request 111go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. aes encrypt 121go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. aes decrypt 147go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. rsa encrypt 163go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. rsa decrypt 178go for the would-be network programmer http://slides.games-with-brains.net/
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. http://golang.org/ go for the would-be network programmer http://slides.games-with-brains.net/201
  • 202. twitter://#golang go for the would-be network programmer http://slides.games-with-brains.net/202