SlideShare a Scribd company logo
go
for the paranoid network programme
r

(now with WebSockets
)

@feyeleanor
1
go for the paranoid network programmer slideshare.net/feyeleanor
twitter://@feyeleanor
go for the paranoid network programmer slideshare.net/feyeleanor
high voltage
networkin
g

concurrenc
y

cryptograph
y

go for the paranoid network programmer slideshare.net/feyeleanor
http
4
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
5
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
6
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
7
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
8
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
9
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
10
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
11
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
12
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
13
https
14
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
15
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
16
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
17
multiple http servers
18
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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 <- tru
e

}(
)

ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil
)

<- don
e

}
go for the paranoid network programmer slideshare.net/feyeleanor
19
package mai
n

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 <- tru
e

}(
)

ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil
)

<- don
e

}
go for the paranoid network programmer slideshare.net/feyeleanor
20
package mai
n

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 <- tru
e

}()
ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil
)

<- don
e

}
go for the paranoid network programmer slideshare.net/feyeleanor
21
package mai
n

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 <- tru
e

}()
ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil
)

<- don
e

}
go for the paranoid network programmer slideshare.net/feyeleanor
22
package mai
n

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 <- tru
e

}()
ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil
)

<- done
}
go for the paranoid network programmer slideshare.net/feyeleanor
23
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
24
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
25
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
26
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
27
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
28
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- tru
e

}(s
)

}

for l := len(f); l > 0; l--
{

<- don
e

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
29
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- tru
e

}(s
)

}
for l := len(f); l > 0; l--
{

<- don
e

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
30
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- tru
e

}(s
)

}
for l := len(f); l > 0; l-- {
<- done
}
}
go for the paranoid network programmer slideshare.net/feyeleanor
31
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- tru
e

}(s
)

}
for _, _ = range f {
<- done
}
}
go for the paranoid network programmer slideshare.net/feyeleanor
32
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- tru
e

}(s
)

}
for range f {
<- done
}
}
go for the paranoid network programmer slideshare.net/feyeleanor
33
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- tru
e

}(s
)

<- done
}
}
go for the paranoid network programmer slideshare.net/feyeleanor
34
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- true
}(s
)

}

for range f
{

<- done
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
35
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func()) {
server()
done <- true
}(s)
}

for range f
{

<- don
e

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
36
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func())
{

server(
)

done <- tru
e

}(s
)

}

for range f
{

<- don
e

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
37
package mai
n

func Spawn(f ...func())
{

done := make(chan bool
)

for _, s := range f
{

go func(server func()) {
server()
done <- true
}(s)
}

for range f
{

<- don
e

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
38
waitgroups
39
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

import . "net/http
"

import "sync
"

func main()
{

HandleFunc("/hello", func(w ResponseWriter, r *Request) {}
)

var servers sync.WaitGrou
p

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 paranoid network programmer slideshare.net/feyeleanor
40
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
41
package mai
n

import . "net/http
"

import "sync
"

func main()
{

HandleFunc("/hello", func(w ResponseWriter, r *Request) {}
)

var servers sync.WaitGrou
p

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 paranoid network programmer slideshare.net/feyeleanor
42
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
43
package mai
n

import
(

. "fmt
"

. "net/http
"

"sync
"

)

var servers sync.WaitGrou
p

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 paranoid network programmer slideshare.net/feyeleanor
44
package mai
n

import
(

. "fmt
"

. "net/http
"

"sync
"

)

var servers sync.WaitGrou
p

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 paranoid network programmer slideshare.net/feyeleanor
45
package mai
n

func Spawn(f ...func())
{

for _, s := range f
{

servers.Add(1
)

go func(server func()) {
defer servers.Done(
)

server(
)

}(s
)

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
46
package mai
n

func Spawn(f ...func())
{

for _, s := range f
{

servers.Add(1)
go func(server func())
{

defer servers.Done()
server(
)

}(s
)

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
47
tcp server
48
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
49
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
50
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
51
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
52
package mai
n

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.Listene
r

if listener, e = net.Listen(p, a); e == nil
{

for
{

if connection, e := listener.Accept(); e == nil
{

go f(connection
)

}
}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
53
package mai
n

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.Listene
r

if listener, e = net.Listen(p, a); e == nil
{

for
{

if connection, e := listener.Accept(); e == nil
{

go f(connection
)

}
}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
54
package mai
n

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
)

}
}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
55
package mai
n

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
)

}
}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
56
tcp client
57
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
58
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
59
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
60
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
61
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
62
package mai
n

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.Con
n

if c, e = net.Dial(p, a); e == nil
{

defer c.Close(
)

f(c
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
63
package mai
n

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.Con
n

if c, e = net.Dial(p, a); e == nil
{

defer c.Close(
)

f(c
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
64
package mai
n

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.Con
n

if c, e = net.Dial(p, a); e == nil
{

defer c.Close()
f(c
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
65
tcp/tls server
66
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

import "crypto/rand
"

import "crypto/tls
"

import . "fmt
"

func main()
{

Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) {
Fprintln(c, "hello world"
)

}
)

}

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
,

}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
67
package mai
n

import "crypto/rand
"

import "crypto/tls
"

import . "fmt
"

func main()
{

Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn)
{

Fprintln(c, "hello world"
)

}
)

}

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
,

}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
68
package mai
n

import "crypto/rand
"

import "crypto/tls
"

import . "fmt
"

func main()
{

Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn)
{

Fprintln(c, "hello world"
)

}
)

}

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
,

}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
69
package mai
n

import "crypto/rand
"

import "crypto/tls
"

import . "fmt
"

func main()
{

Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn)
{

Fprintln(c, "hello world"
)

}
)

}

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
,

}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
70
package mai
n

import "crypto/rand
"

import "crypto/tls
"

import . "fmt
"

func main()
{

Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn)
{

Fprintln(c, "hello world"
)

}
)

}

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
,

}
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
71
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
72
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
73
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
74
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
75
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
76
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
77
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
78
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
79
package mai
n

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 c, e := listener.Accept(); e == nil
{

go Handle(c, f
)

}
}
}
}

func Handle(c net.Conn, f func(net.Conn))
{

defer c.Close(
)

f(c
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
80
tcp/tls client
81
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

import "bufio
"

import "crypto/tls
"

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
)

}

}
)

}

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
,

}
}

go for the paranoid network programmer slideshare.net/feyeleanor
82
package mai
n

import "bufio
"

import "crypto/tls
"

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
)

}

}
)

}

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
,

}
}

go for the paranoid network programmer slideshare.net/feyeleanor
83
package mai
n

import "bufio
"

import "crypto/tls
"

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
)

}

}
)

}

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
,

}
}

go for the paranoid network programmer slideshare.net/feyeleanor
84
package mai
n

import "bufio
"

import "crypto/tls
"

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
)

}

}
)

}

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
,

}
}

go for the paranoid network programmer slideshare.net/feyeleanor
85
package mai
n

import "bufio
"

import "crypto/tls
"

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
)

}

}
)

}

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
,

}
}

go for the paranoid network programmer slideshare.net/feyeleanor
86
package mai
n

import "bufio
"

import "crypto/tls
"

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
)

}

}
)

}

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 paranoid network programmer slideshare.net/feyeleanor
87
package mai
n

import "bufio
"

import "crypto/tls
"

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
)

}

}
)

}

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 paranoid network programmer slideshare.net/feyeleanor
88
udp serve
89
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
90
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
91
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
92
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
93
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
94
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
95
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
96
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
97
package mai
n

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]
)

}
}
}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
98
package mai
n

import "net
"

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
{

ServeUDP(conn, func(c *net.UDPAddr, b []byte)
{

f(conn, c, b
)

})
}
}
}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

for b := make([]byte, 1024); ; b = make([]byte, 1024)
{

if n, client, e := c.ReadFromUDP(b); e == nil
{

go f(client, b[:n]
)

}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
99
package mai
n

import "net
"

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
{

ServeUDP(conn, func(c *net.UDPAddr, b []byte)
{

f(conn, c, b
)

})
}
}
}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

for b := make([]byte, 1024); ; b = make([]byte, 1024) {
if n, client, e := c.ReadFromUDP(b); e == nil
{

go f(client, b[:n]
)

}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
100
package mai
n

import "net
"

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
{

ServeUDP(conn, func(c *net.UDPAddr, b []byte)
{

f(conn, c, b
)

})
}
}
}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

for b := make([]byte, 1024); ; b = make([]byte, 1024) {
if n, client, e := c.ReadFromUDP(b); e == nil
{

go f(client, b[:n]
)

}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
101
package mai
n

import "net
"

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
{

ServeUDP(conn, func(c *net.UDPAddr, b []byte)
{

f(conn, c, b
)

})
}
}
}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

for b := make([]byte, 1024); ; b = make([]byte, 1024) {
if n, client, e := c.ReadFromUDP(b); e == nil
{

go f(client, b[:n]
)

}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
102
package mai
n

import "net
"

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
{

ServeUDP(conn, func(c *net.UDPAddr, b []byte)
{

f(conn, c, b
)

})
}
}
}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

for b := make([]byte, 1024); ; b = make([]byte, 1024) {
if n, client, e := c.ReadFromUDP(b); e == nil
{

go f(client, b[:n]
)

}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
103
package mai
n

import "net
"

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
{

ServeUDP(conn, func(c *net.UDPAddr, b []byte)
{

f(conn, c, b
)

})
}
}
}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

for b := make([]byte, 1024); ; b = make([]byte, 1024) {
if n, client, e := c.ReadFromUDP(b); e == nil
{

go f(client, b[:n]
)

}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
104
package mai
n

import "net
"

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
{

ServeUDP(conn, func(c *net.UDPAddr, b []byte)
{

f(conn, c, b
)

})
}
}
}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

for b := make([]byte, 1024); ; b = make([]byte, 1024)
{

if n, client, e := c.ReadFromUDP(b); e == nil
{

go f(client, b[:n]
)

}
}

}
go for the paranoid network programmer slideshare.net/feyeleanor
105
udp request
106
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
107
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
108
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
109
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
110
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
111
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
112
aes encrypt
113
go for the paranoid network programmer slideshare.net/feyeleanor
go for the paranoid network programmer slideshare.net/feyeleanor
114
package mai
n

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
)

}

}
)

}

func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte))
{

// see udp serv
e

}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

// see udp serv
e

}
go for the paranoid network programmer slideshare.net/feyeleanor
115
package mai
n

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
)

}

}
)

}

func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte))
{

// see udp serv
e

}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

// see udp serv
e

}
go for the paranoid network programmer slideshare.net/feyeleanor
116
package mai
n

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
)

}

}
)

}

func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte))
{

// see udp serv
e

}

func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte))
{

// see udp serv
e

}
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize -
p

b = append(b, make([]byte, p)…) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
117
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize -
p

b = append(b, make([]byte, p)…) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
118
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize -
p

b = append(b, make([]byte, p)…) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
119
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize -
p

b = append(b, make([]byte, p)…) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
120
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize - p
b = append(b, make([]byte, p)…) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
121
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize - p
b = append(b, make([]byte, p)...) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
122
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize - p
b = append(b, make([]byte, p)...) // padding with NUL!!!!
}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
123
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Block
if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize -
p

b = append(b, make([]byte, p)...) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
124
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func Encrypt(m, k string) (o []byte, e error)
{

if o, e = PaddedBuffer([]byte(m)); e == nil
{

var b cipher.Block
if b, e = aes.NewCipher([]byte(k)); e == nil
{

o = CryptBlocks(o, b
)

}
}

retur
n

}

func PaddedBuffer(m []byte) (b []byte, e error)
{

b = append(b, m...
)

if p := len(b) % aes.BlockSize; p != 0
{

p = aes.BlockSize -
p

b = append(b, make([]byte, p)...) // padding with NUL!!!
!

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
125
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
126
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
127
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
128
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
129
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
130
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
131
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
132
package mai
n

import "crypto/aes
"

import "crypto/cipher
"

func CryptBlocks(b []byte, c cipher.Block) (o []byte)
{

o = make([]byte, aes.BlockSize + len(b)
)

copy(o, IV()
)

enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize]
)

enc.CryptBlocks(o[aes.BlockSize:], b
)

retur
n

}

func IV() (b []byte)
{

b = make([]byte, aes.BlockSize
)

if _, e := rand.Read(b); e != nil
{

panic(e
)

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
133
aes decrypt
134
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

import . "fmt
"

import "net
"

const AES_KEY = "0123456789012345
"

func main()
{

Dial(":1025", func(conn net.Conn) {
RequestMessage(conn, func(m []byte)
{

if m, e := Decrypt(m, AES_KEY); e == nil
{

Printf("%sn", m
)

}

}
)

}
)

}

func Dial(a string, f func(net.Conn))
{

// see udp reques
t

}

go for the paranoid network programmer slideshare.net/feyeleanor
135
package mai
n

import . "fmt
"

import "net
"

const AES_KEY = "0123456789012345
"

func main()
{

Dial(":1025", func(conn net.Conn) {
RequestMessage(conn, func(m []byte) {
if m, e := Decrypt(m, AES_KEY); e == nil
{

Printf("%sn", m
)

}

}
)

}
)

}

func Dial(a string, f func(net.Conn))
{

// see udp reques
t

}

go for the paranoid network programmer slideshare.net/feyeleanor
136
package mai
n

import . "fmt
"

import "net
"

const AES_KEY = "0123456789012345"
func main()
{

Dial(":1025", func(conn net.Conn) {
RequestMessage(conn, func(m []byte) {
if m, e := Decrypt(m, AES_KEY); e == nil
{

Printf("%sn", m
)

}

}
)

}
)

}

func Dial(a string, f func(net.Conn))
{

// see udp reques
t

}

go for the paranoid network programmer slideshare.net/feyeleanor
137
package mai
n

import "net
"

func RequestMessage(conn net.Conn, f func([]byte)) (e error)
{

if _, e = conn.Write([]byte("n")); e == nil
{

m := make([]byte, 1024
)

var n in
t

if n, e = conn.Read(m); e == nil
{

f(m[:n]
)

}

}

retur
n

}

go for the paranoid network programmer slideshare.net/feyeleanor
138
package mai
n

import "net
"

func RequestMessage(conn net.Conn, f func([]byte)) (e error)
{

if _, e = conn.Write([]byte("n")); e == nil
{

m := make([]byte, 1024
)

var n in
t

if n, e = conn.Read(m); e == nil
{

f(m[:n]
)

}

}

retur
n

}

go for the paranoid network programmer slideshare.net/feyeleanor
139
package mai
n

import "net
"

func RequestMessage(conn net.Conn, f func([]byte)) (e error)
{

if _, e = conn.Write([]byte("n")); e == nil
{

m := make([]byte, 1024
)

var n in
t

if n, e = conn.Read(m); e == nil
{

f(m[:n]
)

}

}

retur
n

}

go for the paranoid network programmer slideshare.net/feyeleanor
140
package mai
n

import "net
"

func RequestMessage(conn net.Conn, f func([]byte)) (e error)
{

if _, e = conn.Write([]byte("n")); e == nil
{

m := make([]byte, 1024
)

var n in
t

if n, e = conn.Read(m); e == nil
{

f(m[:n]
)

}

}

retur
n

}

go for the paranoid network programmer slideshare.net/feyeleanor
141
package mai
n

import "net
"

func RequestMessage(conn net.Conn, f func([]byte)) (e error)
{

if _, e = conn.Write([]byte("n")); e == nil
{

m := make([]byte, 1024
)

var n in
t

if n, e = conn.Read(m); e == nil
{

f(m[:n]
)

}

}

retur
n

}

go for the paranoid network programmer slideshare.net/feyeleanor
142
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
143
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
144
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
145
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
146
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
147
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
148
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
149
package mai
n

import "crypto/cipher
"

import "crypto/aes
"

func Decrypt(m []byte, k string) (r []byte, e error)
{

var b cipher.Bloc
k

if b, e = aes.NewCipher([]byte(k)); e == nil
{

var iv []byt
e

iv, m = Unpack(m
)

c := cipher.NewCBCDecrypter(b, iv
)

r = make([]byte, len(m)
)

c.CryptBlocks(r, m
)

}

retur
n

}

func Unpack(m []byte) (iv, r []byte)
{

return m[:aes.BlockSize], m[aes.BlockSize:
]

}
go for the paranoid network programmer slideshare.net/feyeleanor
150
rsa encrypt
151
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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.PublicKe
y

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
)

}

}

retur
n

}
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
152
package mai
n

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
)

}

}

retur
n

}
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
153
package mai
n

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.PublicKe
y

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
)

}

}

retur
n

}
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
154
package mai
n

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.PublicKe
y

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
)

}

}

retur
n

}
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
155
package mai
n

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.PublicKe
y

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
)

}

}

retur
n

}
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
156
package mai
n

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.PublicKe
y

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
)

}

}

retur
n

}
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
157
package mai
n

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.PublicKe
y

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
)

}

}

retur
n

}
)

}
go for the paranoid network programmer slideshare.net/feyeleanor
158
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
159
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
160
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
161
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
162
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
163
rsa decrypt
164
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
165
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
166
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
167
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
168
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
169
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
170
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
171
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
172
package mai
n

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
)

}

}

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
173
package mai
n

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
)

}

}

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
174
package mai
n

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
)

}

}

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
175
package mai
n

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
)

}

}

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
176
package mai
n

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
)

}

}

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
177
package mai
n

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
)

}

}

}

retur
n

}
go for the paranoid network programmer slideshare.net/feyeleanor
178
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
179
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
180
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
181
package mai
n

import "bytes
"

import “crypto/rsa
"

import "encoding/gob
"

import "net
"

func SendKey(c *net.UDPConn, k rsa.PublicKey, f func())
{

var b bytes.Buffe
r

if e := gob.NewEncoder(&b).Encode(k); e == nil
{

if _, e = c.Write(b.Bytes()); e == nil
{

f(
)

}

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
182
package mai
n

import "bytes
"

import “crypto/rsa
"

import "encoding/gob
"

import "net
"

func SendKey(c *net.UDPConn, k rsa.PublicKey, f func())
{

var b bytes.Buffe
r

if e := gob.NewEncoder(&b).Encode(k); e == nil
{

if _, e = c.Write(b.Bytes()); e == nil
{

f(
)

}

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
183
package mai
n

import "bytes
"

import “crypto/rsa
"

import "encoding/gob
"

import "net
"

func SendKey(c *net.UDPConn, k rsa.PublicKey, f func())
{

var b bytes.Buffe
r

if e := gob.NewEncoder(&b).Encode(k); e == nil
{

if _, e = c.Write(b.Bytes()); e == nil
{

f(
)

}

}

}
go for the paranoid network programmer slideshare.net/feyeleanor
184
package mai
n

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 paranoid network programmer slideshare.net/feyeleanor
185
serving websockets
186
go for the paranoid network programmer slideshare.net/feyeleanor
ws_hello.htm
l

<!DOCTYPE html
>

<html
>

<head
>

<meta charset='UTF-8' /
>

<title>WEBSOCKET HELLO</title
>

<script src="js"></script
>

</head
>

<body></body
>

</html
>

ws_hello.j
s

window.onload = function()
{

var socket = new WebSocket("ws://localhost:3000/hello")
;

socket.onmessage = m =>
{

div = document.createElement("div")
;

div.innerText = JSON.parse(m.data)
;

document.body.append(div)
;

}
;

}

go for the paranoid network programmer slideshare.net/feyeleanor
187
ws_hello.htm
l

<!DOCTYPE html
>

<html
>

<head
>

<meta charset='UTF-8' /
>

<title>WEBSOCKET HELLO</title
>

<script src="js"></script
>

</head
>

<body></body
>

</html
>

ws_hello.j
s

window.onload = function()
{

var socket = new WebSocket("ws://localhost:3000/hello")
;

socket.onmessage = m =>
{

div = document.createElement("div")
;

div.innerText = JSON.parse(m.data)
;

document.body.append(div)
;

}
;

}

go for the paranoid network programmer slideshare.net/feyeleanor
188
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

import "io/ioutil
"

import "net/http
"

func ServeFile(route, name, mime_type string)
{

b, _ := ioutil.ReadFile(name
)

http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request)
{

w.Header().Set("Content-Type", mime_type
)

fmt.Fprint(w, string(b)
)

}
)

}

func main()
{

http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn)
{

websocket.JSON.Send(ws, "Hello"
)

})
)

ServeFile("/", "ws_hello.html", "text/html"
)

ServeFile("/js", "ws_hello.js", "application/javascript"
)

http.ListenAndServe(":3000", nil
)

}

go for the paranoid network programmer slideshare.net/feyeleanor
189
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

import "io/ioutil
"

import "net/http
"

func ServeFile(route, name, mime_type string)
{

b, _ := ioutil.ReadFile(name
)

http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request)
{

w.Header().Set("Content-Type", mime_type
)

fmt.Fprint(w, string(b)
)

}
)

}

func main()
{

http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn)
{

websocket.JSON.Send(ws, "Hello"
)

})
)

ServeFile("/", "ws_hello.html", "text/html"
)

ServeFile("/js", "ws_hello.js", "application/javascript"
)

http.ListenAndServe(":3000", nil
)

}

go for the paranoid network programmer slideshare.net/feyeleanor
190
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

import "io/ioutil
"

import "net/http
"

func ServeFile(route, name, mime_type string)
{

b, _ := ioutil.ReadFile(name
)

http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request)
{

w.Header().Set("Content-Type", mime_type)
fmt.Fprint(w, string(b)
)

}
)

}

func main()
{

http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn)
{

websocket.JSON.Send(ws, "Hello"
)

})
)

ServeFile("/", "ws_hello.html", "text/html"
)

ServeFile("/js", "ws_hello.js", "application/javascript"
)

http.ListenAndServe(":3000", nil
)

}

go for the paranoid network programmer slideshare.net/feyeleanor
191
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

import "io/ioutil
"

import "net/http
"

func ServeFile(route, name, mime_type string)
{

b, _ := ioutil.ReadFile(name
)

http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request)
{

w.Header().Set("Content-Type", mime_type
)

fmt.Fprint(w, string(b)
)

}
)

}

func main()
{

http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn)
{

websocket.JSON.Send(ws, "Hello"
)

})
)

ServeFile("/", "ws_hello.html", "text/html"
)

ServeFile("/js", "ws_hello.js", "application/javascript"
)

http.ListenAndServe(":3000", nil
)

}

go for the paranoid network programmer slideshare.net/feyeleanor
192
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

import "io/ioutil
"

import "net/http
"

func ServeFile(route, name, mime_type string)
{

b, _ := ioutil.ReadFile(name
)

http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request)
{

w.Header().Set("Content-Type", mime_type
)

fmt.Fprint(w, string(b)
)

}
)

}

func main()
{

http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn)
{

websocket.JSON.Send(ws, "Hello"
)

})
)

ServeFile("/", "ws_hello.html", "text/html"
)

ServeFile("/js", "ws_hello.js", "application/javascript"
)

http.ListenAndServe(":3000", nil
)

}

go for the paranoid network programmer slideshare.net/feyeleanor
193
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

import "io/ioutil
"

import "net/http
"

func ServeFile(route, name, mime_type string)
{

b, _ := ioutil.ReadFile(name
)

http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request)
{

w.Header().Set("Content-Type", mime_type
)

fmt.Fprint(w, string(b)
)

}
)

}

func main()
{

http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn)
{

websocket.JSON.Send(ws, "Hello"
)

})
)

ServeFile("/", "ws_hello.html", "text/html"
)

ServeFile("/js", "ws_hello.js", "application/javascript"
)

http.ListenAndServe(":3000", nil
)

}

go for the paranoid network programmer slideshare.net/feyeleanor
194
accessing websockets
195
go for the paranoid network programmer slideshare.net/feyeleanor
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

const SERVER = "ws://localhost:3000/hello
"

const ADDRESS = "http://localhost/
"

func main()
{

if ws, e := websocket.Dial(SERVER, "", ADDRESS); e == nil
{

var s strin
g

if e := websocket.JSON.Receive(ws, &s); e == nil
{

fmt.Println(s
)

}

}

}

go for the paranoid network programmer slideshare.net/feyeleanor
196
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

const SERVER = "ws://localhost:3000/hello
"

const ADDRESS = "http://localhost/
"

func main()
{

if ws, e := websocket.Dial(SERVER, "", ADDRESS); e == nil
{

var s strin
g

if e := websocket.JSON.Receive(ws, &s); e == nil
{

fmt.Println(s
)

}

}

}

go for the paranoid network programmer slideshare.net/feyeleanor
197
package mai
n

import "fmt
"

import "golang.org/x/net/websocket
"

const SERVER = "ws://localhost:3000/hello
"

const ADDRESS = "http://localhost/
"

func main()
{

if ws, e := websocket.Dial(SERVER, "", ADDRESS); e == nil
{

var s string
if e := websocket.JSON.Receive(ws, &s); e == nil
{

fmt.Println(s
)

}

}

}

go for the paranoid network programmer slideshare.net/feyeleanor
198
twitter://@feyeleanor
go for the paranoid network programmer slideshare.net/feyeleanor
Ad

More Related Content

What's hot (20)

Abusing text/template for data transformation
Abusing text/template for data transformationAbusing text/template for data transformation
Abusing text/template for data transformation
Arnaud Porterie
 
Whispered secrets
Whispered secretsWhispered secrets
Whispered secrets
Eleanor McHugh
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & C
Eleanor McHugh
 
08 php-files
08 php-files08 php-files
08 php-files
hoangphuc2587
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
Aaron Patterson
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
Lin Yo-An
 
What's New in PHP 5.5
What's New in PHP 5.5What's New in PHP 5.5
What's New in PHP 5.5
Corey Ballou
 
Pdr ppt
Pdr pptPdr ppt
Pdr ppt
sid1232086
 
C99[2]
C99[2]C99[2]
C99[2]
guest8914af
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
Paweł Rusin
 
Rust-lang
Rust-langRust-lang
Rust-lang
Anthony Broad-Crawford
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2
Kazuho Oku
 
C99
C99C99
C99
sifo12
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
niklal
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
Kazuho Oku
 
Functional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipperFunctional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipper
osfameron
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
Alexandre Masselot
 
The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212
Mahmoud Samir Fayed
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
Phillip Trelford
 
Abusing text/template for data transformation
Abusing text/template for data transformationAbusing text/template for data transformation
Abusing text/template for data transformation
Arnaud Porterie
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & C
Eleanor McHugh
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
Lin Yo-An
 
What's New in PHP 5.5
What's New in PHP 5.5What's New in PHP 5.5
What's New in PHP 5.5
Corey Ballou
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2
Kazuho Oku
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
niklal
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
Kazuho Oku
 
Functional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipperFunctional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipper
osfameron
 
The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212
Mahmoud Samir Fayed
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
Phillip Trelford
 

Similar to Go for the paranoid network programmer, 3rd edition (20)

Go for the would be network programmer
Go for the would be network programmerGo for the would be network programmer
Go for the would be network programmer
Eleanor McHugh
 
Go for the paranoid network programmer
Go for the paranoid network programmerGo for the paranoid network programmer
Go for the paranoid network programmer
Eleanor McHugh
 
Iss letcure 7_8
Iss letcure 7_8Iss letcure 7_8
Iss letcure 7_8
Ali Habeeb
 
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
 
goatwork2014
goatwork2014goatwork2014
goatwork2014
Bryan Liles
 
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
Hean Hong Leong
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
DigitalOcean
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of Go
Frank Müller
 
Case EasyLocus
Case EasyLocusCase EasyLocus
Case EasyLocus
Henrique Holanda
 
TDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case EasylocusTDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case Easylocus
tdc-globalcode
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
Ismael Celis
 
Composer for busy developers - DPC13
Composer for busy developers - DPC13Composer for busy developers - DPC13
Composer for busy developers - DPC13
Rafael Dohms
 
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
DynamicInfraDays
 
Netty from the trenches
Netty from the trenchesNetty from the trenches
Netty from the trenches
Jordi Gerona
 
H2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy WangH2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy Wang
Sri Ambati
 
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of PedestalInterceptors: Into the Core of Pedestal
Interceptors: Into the Core of Pedestal
Kent Ohashi
 
rioinfo2012
rioinfo2012rioinfo2012
rioinfo2012
Juan Lopes
 
Meetup talk: Readying your Go Webservice
Meetup talk: Readying your Go WebserviceMeetup talk: Readying your Go Webservice
Meetup talk: Readying your Go Webservice
Ralph Ligtenberg
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with Varnish
Varnish Software
 
Go for the would be network programmer
Go for the would be network programmerGo for the would be network programmer
Go for the would be network programmer
Eleanor McHugh
 
Go for the paranoid network programmer
Go for the paranoid network programmerGo for the paranoid network programmer
Go for the paranoid network programmer
Eleanor McHugh
 
Iss letcure 7_8
Iss letcure 7_8Iss letcure 7_8
Iss letcure 7_8
Ali Habeeb
 
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
 
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
Hean Hong Leong
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
DigitalOcean
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of Go
Frank Müller
 
TDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case EasylocusTDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case Easylocus
tdc-globalcode
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
Ismael Celis
 
Composer for busy developers - DPC13
Composer for busy developers - DPC13Composer for busy developers - DPC13
Composer for busy developers - DPC13
Rafael Dohms
 
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
DynamicInfraDays
 
Netty from the trenches
Netty from the trenchesNetty from the trenches
Netty from the trenches
Jordi Gerona
 
H2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy WangH2O World - Intro to R, Python, and Flow - Amy Wang
H2O World - Intro to R, Python, and Flow - Amy Wang
Sri Ambati
 
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of PedestalInterceptors: Into the Core of Pedestal
Interceptors: Into the Core of Pedestal
Kent Ohashi
 
Meetup talk: Readying your Go Webservice
Meetup talk: Readying your Go WebserviceMeetup talk: Readying your Go Webservice
Meetup talk: Readying your Go Webservice
Ralph Ligtenberg
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with Varnish
Varnish Software
 
Ad

More from Eleanor McHugh (20)

Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre TalesNever Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Eleanor McHugh
 
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
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.pdf
Eleanor McHugh
 
Generics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient CollectionsGenerics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient Collections
Eleanor 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 Integrity
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 go
Eleanor 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 redux
Eleanor McHugh
 
Identity & trust in Monitored Spaces
Identity & trust in Monitored SpacesIdentity & trust in Monitored Spaces
Identity & trust in Monitored Spaces
Eleanor 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 Design
Eleanor 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 design
Eleanor McHugh
 
Anonymity, identity, trust
Anonymity, identity, trustAnonymity, identity, trust
Anonymity, identity, trust
Eleanor 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 Go
Eleanor McHugh
 
Distributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at ScaleDistributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at Scale
Eleanor 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 go
Eleanor McHugh
 
Anonymity, trust, accountability
Anonymity, trust, accountabilityAnonymity, trust, accountability
Anonymity, trust, accountability
Eleanor McHugh
 
Implementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CImplementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & C
Eleanor McHugh
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
Eleanor McHugh
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
Eleanor McHugh
 
Privacy is always a requirement
Privacy is always a requirementPrivacy is always a requirement
Privacy is always a requirement
Eleanor McHugh
 
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre TalesNever Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Eleanor McHugh
 
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
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.pdf
Eleanor McHugh
 
Generics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient CollectionsGenerics, Reflection, and Efficient Collections
Generics, Reflection, and Efficient Collections
Eleanor 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 Integrity
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 go
Eleanor 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 redux
Eleanor McHugh
 
Identity & trust in Monitored Spaces
Identity & trust in Monitored SpacesIdentity & trust in Monitored Spaces
Identity & trust in Monitored Spaces
Eleanor 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 Design
Eleanor 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 design
Eleanor McHugh
 
Anonymity, identity, trust
Anonymity, identity, trustAnonymity, identity, trust
Anonymity, identity, trust
Eleanor 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 Go
Eleanor McHugh
 
Distributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at ScaleDistributed Ledgers: Anonymity & Immutability at Scale
Distributed Ledgers: Anonymity & Immutability at Scale
Eleanor 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 go
Eleanor McHugh
 
Anonymity, trust, accountability
Anonymity, trust, accountabilityAnonymity, trust, accountability
Anonymity, trust, accountability
Eleanor McHugh
 
Implementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & CImplementing Virtual Machines in Ruby & C
Implementing Virtual Machines in Ruby & C
Eleanor McHugh
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
Eleanor McHugh
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
Eleanor McHugh
 
Privacy is always a requirement
Privacy is always a requirementPrivacy is always a requirement
Privacy is always a requirement
Eleanor McHugh
 
Ad

Recently uploaded (20)

Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 

Go for the paranoid network programmer, 3rd edition

  • 1. go for the paranoid network programme r (now with WebSockets ) @feyeleanor 1 go for the paranoid network programmer slideshare.net/feyeleanor
  • 2. twitter://@feyeleanor go for the paranoid network programmer slideshare.net/feyeleanor
  • 3. high voltage networkin g concurrenc y cryptograph y go for the paranoid network programmer slideshare.net/feyeleanor
  • 4. http 4 go for the paranoid network programmer slideshare.net/feyeleanor
  • 5. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 5
  • 6. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 6
  • 7. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 7
  • 8. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 8
  • 9. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 9
  • 10. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 10
  • 11. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 11
  • 12. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 12
  • 13. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 13
  • 14. https 14 go for the paranoid network programmer slideshare.net/feyeleanor
  • 15. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 15
  • 16. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 16
  • 17. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 17
  • 18. multiple http servers 18 go for the paranoid network programmer slideshare.net/feyeleanor
  • 19. package mai n 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 <- tru e }( ) ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil ) <- don e } go for the paranoid network programmer slideshare.net/feyeleanor 19
  • 20. package mai n 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 <- tru e }( ) ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil ) <- don e } go for the paranoid network programmer slideshare.net/feyeleanor 20
  • 21. package mai n 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 <- tru e }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil ) <- don e } go for the paranoid network programmer slideshare.net/feyeleanor 21
  • 22. package mai n 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 <- tru e }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil ) <- don e } go for the paranoid network programmer slideshare.net/feyeleanor 22
  • 23. package mai n 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 <- tru e }() ListenAndServeTLS(":1025", "cert.pem", "key.pem", nil ) <- done } go for the paranoid network programmer slideshare.net/feyeleanor 23
  • 24. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 24
  • 25. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 25
  • 26. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 26
  • 27. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 27
  • 28. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 28
  • 29. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- tru e }(s ) } for l := len(f); l > 0; l-- { <- don e } } go for the paranoid network programmer slideshare.net/feyeleanor 29
  • 30. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- tru e }(s ) } for l := len(f); l > 0; l-- { <- don e } } go for the paranoid network programmer slideshare.net/feyeleanor 30
  • 31. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- tru e }(s ) } for l := len(f); l > 0; l-- { <- done } } go for the paranoid network programmer slideshare.net/feyeleanor 31
  • 32. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- tru e }(s ) } for _, _ = range f { <- done } } go for the paranoid network programmer slideshare.net/feyeleanor 32
  • 33. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- tru e }(s ) } for range f { <- done } } go for the paranoid network programmer slideshare.net/feyeleanor 33
  • 34. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- tru e }(s ) <- done } } go for the paranoid network programmer slideshare.net/feyeleanor 34
  • 35. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- true }(s ) } for range f { <- done } } go for the paranoid network programmer slideshare.net/feyeleanor 35
  • 36. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server() done <- true }(s) } for range f { <- don e } } go for the paranoid network programmer slideshare.net/feyeleanor 36
  • 37. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server( ) done <- tru e }(s ) } for range f { <- don e } } go for the paranoid network programmer slideshare.net/feyeleanor 37
  • 38. package mai n func Spawn(f ...func()) { done := make(chan bool ) for _, s := range f { go func(server func()) { server() done <- true }(s) } for range f { <- don e } } go for the paranoid network programmer slideshare.net/feyeleanor 38
  • 39. waitgroups 39 go for the paranoid network programmer slideshare.net/feyeleanor
  • 40. package mai n import . "net/http " import "sync " func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) {} ) var servers sync.WaitGrou p 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 paranoid network programmer slideshare.net/feyeleanor 40
  • 41. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 41
  • 42. package mai n import . "net/http " import "sync " func main() { HandleFunc("/hello", func(w ResponseWriter, r *Request) {} ) var servers sync.WaitGrou p 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 paranoid network programmer slideshare.net/feyeleanor 42
  • 43. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 43
  • 44. package mai n import ( . "fmt " . "net/http " "sync " ) var servers sync.WaitGrou p 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 paranoid network programmer slideshare.net/feyeleanor 44
  • 45. package mai n import ( . "fmt " . "net/http " "sync " ) var servers sync.WaitGrou p 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 paranoid network programmer slideshare.net/feyeleanor 45
  • 46. package mai n func Spawn(f ...func()) { for _, s := range f { servers.Add(1 ) go func(server func()) { defer servers.Done( ) server( ) }(s ) } } go for the paranoid network programmer slideshare.net/feyeleanor 46
  • 47. package mai n func Spawn(f ...func()) { for _, s := range f { servers.Add(1) go func(server func()) { defer servers.Done() server( ) }(s ) } } go for the paranoid network programmer slideshare.net/feyeleanor 47
  • 48. tcp server 48 go for the paranoid network programmer slideshare.net/feyeleanor
  • 49. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 49
  • 50. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 50
  • 51. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 51
  • 52. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 52
  • 53. package mai n 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.Listene r if listener, e = net.Listen(p, a); e == nil { for { if connection, e := listener.Accept(); e == nil { go f(connection ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 53
  • 54. package mai n 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.Listene r if listener, e = net.Listen(p, a); e == nil { for { if connection, e := listener.Accept(); e == nil { go f(connection ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 54
  • 55. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 55
  • 56. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 56
  • 57. tcp client 57 go for the paranoid network programmer slideshare.net/feyeleanor
  • 58. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 58
  • 59. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 59
  • 60. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 60
  • 61. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 61
  • 62. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 62
  • 63. package mai n 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.Con n if c, e = net.Dial(p, a); e == nil { defer c.Close( ) f(c ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 63
  • 64. package mai n 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.Con n if c, e = net.Dial(p, a); e == nil { defer c.Close( ) f(c ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 64
  • 65. package mai n 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.Con n if c, e = net.Dial(p, a); e == nil { defer c.Close() f(c ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 65
  • 66. tcp/tls server 66 go for the paranoid network programmer slideshare.net/feyeleanor
  • 67. package mai n import "crypto/rand " import "crypto/tls " import . "fmt " func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world" ) } ) } 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 , } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 67
  • 68. package mai n import "crypto/rand " import "crypto/tls " import . "fmt " func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world" ) } ) } 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 , } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 68
  • 69. package mai n import "crypto/rand " import "crypto/tls " import . "fmt " func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world" ) } ) } 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 , } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 69
  • 70. package mai n import "crypto/rand " import "crypto/tls " import . "fmt " func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world" ) } ) } 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 , } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 70
  • 71. package mai n import "crypto/rand " import "crypto/tls " import . "fmt " func main() { Listen(":1025", ConfigTLS("scert", "skey"), func(c *tls.Conn) { Fprintln(c, "hello world" ) } ) } 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 , } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 71
  • 72. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 72
  • 73. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 73
  • 74. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 74
  • 75. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 75
  • 76. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 76
  • 77. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 77
  • 78. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 78
  • 79. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 79
  • 80. package mai n 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 c, e := listener.Accept(); e == nil { go Handle(c, f ) } } } } func Handle(c net.Conn, f func(net.Conn)) { defer c.Close( ) f(c ) } go for the paranoid network programmer slideshare.net/feyeleanor 80
  • 81. tcp/tls client 81 go for the paranoid network programmer slideshare.net/feyeleanor
  • 82. package mai n import "bufio " import "crypto/tls " 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 ) } } ) } 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 , } } go for the paranoid network programmer slideshare.net/feyeleanor 82
  • 83. package mai n import "bufio " import "crypto/tls " 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 ) } } ) } 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 , } } go for the paranoid network programmer slideshare.net/feyeleanor 83
  • 84. package mai n import "bufio " import "crypto/tls " 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 ) } } ) } 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 , } } go for the paranoid network programmer slideshare.net/feyeleanor 84
  • 85. package mai n import "bufio " import "crypto/tls " 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 ) } } ) } 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 , } } go for the paranoid network programmer slideshare.net/feyeleanor 85
  • 86. package mai n import "bufio " import "crypto/tls " 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 ) } } ) } 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 , } } go for the paranoid network programmer slideshare.net/feyeleanor 86
  • 87. package mai n import "bufio " import "crypto/tls " 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 ) } } ) } 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 paranoid network programmer slideshare.net/feyeleanor 87
  • 88. package mai n import "bufio " import "crypto/tls " 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 ) } } ) } 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 paranoid network programmer slideshare.net/feyeleanor 88
  • 89. udp serve 89 go for the paranoid network programmer slideshare.net/feyeleanor
  • 90. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 90
  • 91. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 91
  • 92. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 92
  • 93. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 93
  • 94. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 94
  • 95. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 95
  • 96. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 96
  • 97. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 97
  • 98. package mai n 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] ) } } } } } go for the paranoid network programmer slideshare.net/feyeleanor 98
  • 99. package mai n import "net " 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 { ServeUDP(conn, func(c *net.UDPAddr, b []byte) { f(conn, c, b ) }) } } } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := c.ReadFromUDP(b); e == nil { go f(client, b[:n] ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 99
  • 100. package mai n import "net " 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 { ServeUDP(conn, func(c *net.UDPAddr, b []byte) { f(conn, c, b ) }) } } } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := c.ReadFromUDP(b); e == nil { go f(client, b[:n] ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 100
  • 101. package mai n import "net " 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 { ServeUDP(conn, func(c *net.UDPAddr, b []byte) { f(conn, c, b ) }) } } } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := c.ReadFromUDP(b); e == nil { go f(client, b[:n] ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 101
  • 102. package mai n import "net " 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 { ServeUDP(conn, func(c *net.UDPAddr, b []byte) { f(conn, c, b ) }) } } } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := c.ReadFromUDP(b); e == nil { go f(client, b[:n] ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 102
  • 103. package mai n import "net " 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 { ServeUDP(conn, func(c *net.UDPAddr, b []byte) { f(conn, c, b ) }) } } } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := c.ReadFromUDP(b); e == nil { go f(client, b[:n] ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 103
  • 104. package mai n import "net " 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 { ServeUDP(conn, func(c *net.UDPAddr, b []byte) { f(conn, c, b ) }) } } } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := c.ReadFromUDP(b); e == nil { go f(client, b[:n] ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 104
  • 105. package mai n import "net " 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 { ServeUDP(conn, func(c *net.UDPAddr, b []byte) { f(conn, c, b ) }) } } } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { for b := make([]byte, 1024); ; b = make([]byte, 1024) { if n, client, e := c.ReadFromUDP(b); e == nil { go f(client, b[:n] ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 105
  • 106. udp request 106 go for the paranoid network programmer slideshare.net/feyeleanor
  • 107. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 107
  • 108. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 108
  • 109. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 109
  • 110. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 110
  • 111. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 111
  • 112. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 112
  • 113. aes encrypt 113 go for the paranoid network programmer slideshare.net/feyeleanor
  • 114. go for the paranoid network programmer slideshare.net/feyeleanor 114 package mai n 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 ) } } ) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { // see udp serv e } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { // see udp serv e }
  • 115. go for the paranoid network programmer slideshare.net/feyeleanor 115 package mai n 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 ) } } ) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { // see udp serv e } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { // see udp serv e }
  • 116. go for the paranoid network programmer slideshare.net/feyeleanor 116 package mai n 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 ) } } ) } func Listen(a string, f func(*net.UDPConn, *net.UDPAddr, []byte)) { // see udp serv e } func ServeUDP(c *net.UDPConn, f func(*net.UDPAddr, []byte)) { // see udp serv e }
  • 117. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)…) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 117
  • 118. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)…) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 118
  • 119. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)…) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 119
  • 120. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)…) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 120
  • 121. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)…) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 121
  • 122. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)...) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 122
  • 123. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)...) // padding with NUL!!!! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 123
  • 124. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)...) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 124
  • 125. package mai n import "crypto/aes " import "crypto/cipher " func Encrypt(m, k string) (o []byte, e error) { if o, e = PaddedBuffer([]byte(m)); e == nil { var b cipher.Block if b, e = aes.NewCipher([]byte(k)); e == nil { o = CryptBlocks(o, b ) } } retur n } func PaddedBuffer(m []byte) (b []byte, e error) { b = append(b, m... ) if p := len(b) % aes.BlockSize; p != 0 { p = aes.BlockSize - p b = append(b, make([]byte, p)...) // padding with NUL!!! ! } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 125
  • 126. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 126
  • 127. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 127
  • 128. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 128
  • 129. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 129
  • 130. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 130
  • 131. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 131
  • 132. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 132
  • 133. package mai n import "crypto/aes " import "crypto/cipher " func CryptBlocks(b []byte, c cipher.Block) (o []byte) { o = make([]byte, aes.BlockSize + len(b) ) copy(o, IV() ) enc := cipher.NewCBCEncrypter(c, o[:aes.BlockSize] ) enc.CryptBlocks(o[aes.BlockSize:], b ) retur n } func IV() (b []byte) { b = make([]byte, aes.BlockSize ) if _, e := rand.Read(b); e != nil { panic(e ) } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 133
  • 134. aes decrypt 134 go for the paranoid network programmer slideshare.net/feyeleanor
  • 135. package mai n import . "fmt " import "net " const AES_KEY = "0123456789012345 " func main() { Dial(":1025", func(conn net.Conn) { RequestMessage(conn, func(m []byte) { if m, e := Decrypt(m, AES_KEY); e == nil { Printf("%sn", m ) } } ) } ) } func Dial(a string, f func(net.Conn)) { // see udp reques t } go for the paranoid network programmer slideshare.net/feyeleanor 135
  • 136. package mai n import . "fmt " import "net " const AES_KEY = "0123456789012345 " func main() { Dial(":1025", func(conn net.Conn) { RequestMessage(conn, func(m []byte) { if m, e := Decrypt(m, AES_KEY); e == nil { Printf("%sn", m ) } } ) } ) } func Dial(a string, f func(net.Conn)) { // see udp reques t } go for the paranoid network programmer slideshare.net/feyeleanor 136
  • 137. package mai n import . "fmt " import "net " const AES_KEY = "0123456789012345" func main() { Dial(":1025", func(conn net.Conn) { RequestMessage(conn, func(m []byte) { if m, e := Decrypt(m, AES_KEY); e == nil { Printf("%sn", m ) } } ) } ) } func Dial(a string, f func(net.Conn)) { // see udp reques t } go for the paranoid network programmer slideshare.net/feyeleanor 137
  • 138. package mai n import "net " func RequestMessage(conn net.Conn, f func([]byte)) (e error) { if _, e = conn.Write([]byte("n")); e == nil { m := make([]byte, 1024 ) var n in t if n, e = conn.Read(m); e == nil { f(m[:n] ) } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 138
  • 139. package mai n import "net " func RequestMessage(conn net.Conn, f func([]byte)) (e error) { if _, e = conn.Write([]byte("n")); e == nil { m := make([]byte, 1024 ) var n in t if n, e = conn.Read(m); e == nil { f(m[:n] ) } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 139
  • 140. package mai n import "net " func RequestMessage(conn net.Conn, f func([]byte)) (e error) { if _, e = conn.Write([]byte("n")); e == nil { m := make([]byte, 1024 ) var n in t if n, e = conn.Read(m); e == nil { f(m[:n] ) } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 140
  • 141. package mai n import "net " func RequestMessage(conn net.Conn, f func([]byte)) (e error) { if _, e = conn.Write([]byte("n")); e == nil { m := make([]byte, 1024 ) var n in t if n, e = conn.Read(m); e == nil { f(m[:n] ) } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 141
  • 142. package mai n import "net " func RequestMessage(conn net.Conn, f func([]byte)) (e error) { if _, e = conn.Write([]byte("n")); e == nil { m := make([]byte, 1024 ) var n in t if n, e = conn.Read(m); e == nil { f(m[:n] ) } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 142
  • 143. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 143
  • 144. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 144
  • 145. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 145
  • 146. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 146
  • 147. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 147
  • 148. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 148
  • 149. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 149
  • 150. package mai n import "crypto/cipher " import "crypto/aes " func Decrypt(m []byte, k string) (r []byte, e error) { var b cipher.Bloc k if b, e = aes.NewCipher([]byte(k)); e == nil { var iv []byt e iv, m = Unpack(m ) c := cipher.NewCBCDecrypter(b, iv ) r = make([]byte, len(m) ) c.CryptBlocks(r, m ) } retur n } func Unpack(m []byte) (iv, r []byte) { return m[:aes.BlockSize], m[aes.BlockSize: ] } go for the paranoid network programmer slideshare.net/feyeleanor 150
  • 151. rsa encrypt 151 go for the paranoid network programmer slideshare.net/feyeleanor
  • 152. package mai n 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.PublicKe y 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 ) } } retur n } ) } go for the paranoid network programmer slideshare.net/feyeleanor 152
  • 153. package mai n 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 ) } } retur n } ) } go for the paranoid network programmer slideshare.net/feyeleanor 153
  • 154. package mai n 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.PublicKe y 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 ) } } retur n } ) } go for the paranoid network programmer slideshare.net/feyeleanor 154
  • 155. package mai n 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.PublicKe y 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 ) } } retur n } ) } go for the paranoid network programmer slideshare.net/feyeleanor 155
  • 156. package mai n 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.PublicKe y 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 ) } } retur n } ) } go for the paranoid network programmer slideshare.net/feyeleanor 156
  • 157. package mai n 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.PublicKe y 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 ) } } retur n } ) } go for the paranoid network programmer slideshare.net/feyeleanor 157
  • 158. package mai n 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.PublicKe y 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 ) } } retur n } ) } go for the paranoid network programmer slideshare.net/feyeleanor 158
  • 159. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 159
  • 160. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 160
  • 161. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 161
  • 162. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 162
  • 163. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 163
  • 164. rsa decrypt 164 go for the paranoid network programmer slideshare.net/feyeleanor
  • 165. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 165
  • 166. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 166
  • 167. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 167
  • 168. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 168
  • 169. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 169
  • 170. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 170
  • 171. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 171
  • 172. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 172
  • 173. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 173
  • 174. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 174
  • 175. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 175
  • 176. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 176
  • 177. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 177
  • 178. package mai n 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 ) } } } retur n } go for the paranoid network programmer slideshare.net/feyeleanor 178
  • 179. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 179
  • 180. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 180
  • 181. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 181
  • 182. package mai n import "bytes " import “crypto/rsa " import "encoding/gob " import "net " func SendKey(c *net.UDPConn, k rsa.PublicKey, f func()) { var b bytes.Buffe r if e := gob.NewEncoder(&b).Encode(k); e == nil { if _, e = c.Write(b.Bytes()); e == nil { f( ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 182
  • 183. package mai n import "bytes " import “crypto/rsa " import "encoding/gob " import "net " func SendKey(c *net.UDPConn, k rsa.PublicKey, f func()) { var b bytes.Buffe r if e := gob.NewEncoder(&b).Encode(k); e == nil { if _, e = c.Write(b.Bytes()); e == nil { f( ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 183
  • 184. package mai n import "bytes " import “crypto/rsa " import "encoding/gob " import "net " func SendKey(c *net.UDPConn, k rsa.PublicKey, f func()) { var b bytes.Buffe r if e := gob.NewEncoder(&b).Encode(k); e == nil { if _, e = c.Write(b.Bytes()); e == nil { f( ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 184
  • 185. package mai n 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 paranoid network programmer slideshare.net/feyeleanor 185
  • 186. serving websockets 186 go for the paranoid network programmer slideshare.net/feyeleanor
  • 187. ws_hello.htm l <!DOCTYPE html > <html > <head > <meta charset='UTF-8' / > <title>WEBSOCKET HELLO</title > <script src="js"></script > </head > <body></body > </html > ws_hello.j s window.onload = function() { var socket = new WebSocket("ws://localhost:3000/hello") ; socket.onmessage = m => { div = document.createElement("div") ; div.innerText = JSON.parse(m.data) ; document.body.append(div) ; } ; } go for the paranoid network programmer slideshare.net/feyeleanor 187
  • 188. ws_hello.htm l <!DOCTYPE html > <html > <head > <meta charset='UTF-8' / > <title>WEBSOCKET HELLO</title > <script src="js"></script > </head > <body></body > </html > ws_hello.j s window.onload = function() { var socket = new WebSocket("ws://localhost:3000/hello") ; socket.onmessage = m => { div = document.createElement("div") ; div.innerText = JSON.parse(m.data) ; document.body.append(div) ; } ; } go for the paranoid network programmer slideshare.net/feyeleanor 188
  • 189. package mai n import "fmt " import "golang.org/x/net/websocket " import "io/ioutil " import "net/http " func ServeFile(route, name, mime_type string) { b, _ := ioutil.ReadFile(name ) http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mime_type ) fmt.Fprint(w, string(b) ) } ) } func main() { http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn) { websocket.JSON.Send(ws, "Hello" ) }) ) ServeFile("/", "ws_hello.html", "text/html" ) ServeFile("/js", "ws_hello.js", "application/javascript" ) http.ListenAndServe(":3000", nil ) } go for the paranoid network programmer slideshare.net/feyeleanor 189
  • 190. package mai n import "fmt " import "golang.org/x/net/websocket " import "io/ioutil " import "net/http " func ServeFile(route, name, mime_type string) { b, _ := ioutil.ReadFile(name ) http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mime_type ) fmt.Fprint(w, string(b) ) } ) } func main() { http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn) { websocket.JSON.Send(ws, "Hello" ) }) ) ServeFile("/", "ws_hello.html", "text/html" ) ServeFile("/js", "ws_hello.js", "application/javascript" ) http.ListenAndServe(":3000", nil ) } go for the paranoid network programmer slideshare.net/feyeleanor 190
  • 191. package mai n import "fmt " import "golang.org/x/net/websocket " import "io/ioutil " import "net/http " func ServeFile(route, name, mime_type string) { b, _ := ioutil.ReadFile(name ) http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mime_type) fmt.Fprint(w, string(b) ) } ) } func main() { http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn) { websocket.JSON.Send(ws, "Hello" ) }) ) ServeFile("/", "ws_hello.html", "text/html" ) ServeFile("/js", "ws_hello.js", "application/javascript" ) http.ListenAndServe(":3000", nil ) } go for the paranoid network programmer slideshare.net/feyeleanor 191
  • 192. package mai n import "fmt " import "golang.org/x/net/websocket " import "io/ioutil " import "net/http " func ServeFile(route, name, mime_type string) { b, _ := ioutil.ReadFile(name ) http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mime_type ) fmt.Fprint(w, string(b) ) } ) } func main() { http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn) { websocket.JSON.Send(ws, "Hello" ) }) ) ServeFile("/", "ws_hello.html", "text/html" ) ServeFile("/js", "ws_hello.js", "application/javascript" ) http.ListenAndServe(":3000", nil ) } go for the paranoid network programmer slideshare.net/feyeleanor 192
  • 193. package mai n import "fmt " import "golang.org/x/net/websocket " import "io/ioutil " import "net/http " func ServeFile(route, name, mime_type string) { b, _ := ioutil.ReadFile(name ) http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mime_type ) fmt.Fprint(w, string(b) ) } ) } func main() { http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn) { websocket.JSON.Send(ws, "Hello" ) }) ) ServeFile("/", "ws_hello.html", "text/html" ) ServeFile("/js", "ws_hello.js", "application/javascript" ) http.ListenAndServe(":3000", nil ) } go for the paranoid network programmer slideshare.net/feyeleanor 193
  • 194. package mai n import "fmt " import "golang.org/x/net/websocket " import "io/ioutil " import "net/http " func ServeFile(route, name, mime_type string) { b, _ := ioutil.ReadFile(name ) http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mime_type ) fmt.Fprint(w, string(b) ) } ) } func main() { http.Handle("/hello", websocket.Handler(func(ws *websocket.Conn) { websocket.JSON.Send(ws, "Hello" ) }) ) ServeFile("/", "ws_hello.html", "text/html" ) ServeFile("/js", "ws_hello.js", "application/javascript" ) http.ListenAndServe(":3000", nil ) } go for the paranoid network programmer slideshare.net/feyeleanor 194
  • 195. accessing websockets 195 go for the paranoid network programmer slideshare.net/feyeleanor
  • 196. package mai n import "fmt " import "golang.org/x/net/websocket " const SERVER = "ws://localhost:3000/hello " const ADDRESS = "http://localhost/ " func main() { if ws, e := websocket.Dial(SERVER, "", ADDRESS); e == nil { var s strin g if e := websocket.JSON.Receive(ws, &s); e == nil { fmt.Println(s ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 196
  • 197. package mai n import "fmt " import "golang.org/x/net/websocket " const SERVER = "ws://localhost:3000/hello " const ADDRESS = "http://localhost/ " func main() { if ws, e := websocket.Dial(SERVER, "", ADDRESS); e == nil { var s strin g if e := websocket.JSON.Receive(ws, &s); e == nil { fmt.Println(s ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 197
  • 198. package mai n import "fmt " import "golang.org/x/net/websocket " const SERVER = "ws://localhost:3000/hello " const ADDRESS = "http://localhost/ " func main() { if ws, e := websocket.Dial(SERVER, "", ADDRESS); e == nil { var s string if e := websocket.JSON.Receive(ws, &s); e == nil { fmt.Println(s ) } } } go for the paranoid network programmer slideshare.net/feyeleanor 198
  • 199. twitter://@feyeleanor go for the paranoid network programmer slideshare.net/feyeleanor
  翻译: