Draft third edition of my #golang network programming and cryptography talk given to the Belfast Gophers Meetup. Now with an introduction to websockets.
An introduction to Go from basics to web through the lens of "Hello World", extracted from the Book "A Go Developer's Notebook" available from http://leanpub.com/GoNotebook
An introduction to secrecy and privacy in software system design with code examples in Go demonstrating secure transport techniques with https, tcp/tls and encrypted udp.
An introduction to Go from basics to web through the lens of "Hello World", extracted from the Book "A Go Developer's Notebook" available from http://leanpub.com/GoNotebook
An introduction to secrecy and privacy in software system design with code examples in Go demonstrating secure transport techniques with https, tcp/tls and encrypted udp.
The case for building software with privacy as a primary concern with a discussion of how privacy and secrecy differ.
This is followed by an introduction to practical cryptographic techniques with code in Go which can be used to secure both communications channels and data stores.
Follow me on Twitter at http://www.twitter.com/cballou or checkout my startup at http://www.pop.co.
In this presentation we will cover the best features and additions in PHP 5.5. You can look forward to the following:
* Support for generators has been added via the yield keyword
* Usage of the new finally keyword in try-catch blocks
* An overview and examples of the new password hashing API
* The foreach control structure now supports unpacking nested arrays into separate variables via the list() construct
* empty() supports arbitrary expressions such as closures returning false
* array and string literal dereferencing
* The Zend Optimiser+ opcode cache (via the new OPcache extension)
Rust
Why do you care about Rust? Who has the time to learn all these new languages? It seems like a new one is popping up every other week and this trend is growing at an exponential rate. Good news, a fair number of them are crafted really well and efficiently solve specific problems. Bad news, how do you keep up with all of this, let alone decide which languages to include in your companies technology portfolio.
Despite the challenges of all these new languages, a majority of developers are intrigued about the idea of becoming a polyglot, but don't know where to begin or don't have the time. In my polyglot travels, there is one language of late that is the sure-fire answer to the above questions, Rust.
In this talk I’ll explore the value behind becoming more polyglotic as a developer, how to pick languages to learn, and then dive deep in the the language of Rust. Which in my opinion, is hands down the best up and coming languages to learn.
About the Presenter
Anthony Broad-Crawford has been a developer since the year 2000 with a short side stint as a semi-professional poker player. Since his transition to software development Anthony has...
1. Built 8 patent receiving technologies
2. Founded two global companies
3. Been a CTO (3x), CPO (1x), and CEO (1x)
and is currently the CTO at Fooda where he manages product, user experience, and engineering. Fooda is predominantly web and mobile technology company focused on bringing great & healthy food from the best restaurant's to people while at the office.
Through his career, in production applications Anthony has used Ruby, Java, Jave (Android), Objective-C and Swift, .NET, Erlang, Scala, Node.JS, LISP, Smalltalk, and even assembly, with his recent favorite, Rust . No, not all at the same time in the same application.
Anthony now spends his time building great teams, that leverage great technology, to build great products, but still looks to codes every chance he can get :)
An enhanced version of the #codemesh2014 talk on network programming in Go. It covers HTTP, HTTPS, TCP/IP, TCP/IP over TLS, UDP and basic cryptographic functions with AES-CBC and RSA.
The case for building software with privacy as a primary concern with a discussion of how privacy and secrecy differ.
This is followed by an introduction to practical cryptographic techniques with code in Go which can be used to secure both communications channels and data stores.
Follow me on Twitter at http://www.twitter.com/cballou or checkout my startup at http://www.pop.co.
In this presentation we will cover the best features and additions in PHP 5.5. You can look forward to the following:
* Support for generators has been added via the yield keyword
* Usage of the new finally keyword in try-catch blocks
* An overview and examples of the new password hashing API
* The foreach control structure now supports unpacking nested arrays into separate variables via the list() construct
* empty() supports arbitrary expressions such as closures returning false
* array and string literal dereferencing
* The Zend Optimiser+ opcode cache (via the new OPcache extension)
Rust
Why do you care about Rust? Who has the time to learn all these new languages? It seems like a new one is popping up every other week and this trend is growing at an exponential rate. Good news, a fair number of them are crafted really well and efficiently solve specific problems. Bad news, how do you keep up with all of this, let alone decide which languages to include in your companies technology portfolio.
Despite the challenges of all these new languages, a majority of developers are intrigued about the idea of becoming a polyglot, but don't know where to begin or don't have the time. In my polyglot travels, there is one language of late that is the sure-fire answer to the above questions, Rust.
In this talk I’ll explore the value behind becoming more polyglotic as a developer, how to pick languages to learn, and then dive deep in the the language of Rust. Which in my opinion, is hands down the best up and coming languages to learn.
About the Presenter
Anthony Broad-Crawford has been a developer since the year 2000 with a short side stint as a semi-professional poker player. Since his transition to software development Anthony has...
1. Built 8 patent receiving technologies
2. Founded two global companies
3. Been a CTO (3x), CPO (1x), and CEO (1x)
and is currently the CTO at Fooda where he manages product, user experience, and engineering. Fooda is predominantly web and mobile technology company focused on bringing great & healthy food from the best restaurant's to people while at the office.
Through his career, in production applications Anthony has used Ruby, Java, Jave (Android), Objective-C and Swift, .NET, Erlang, Scala, Node.JS, LISP, Smalltalk, and even assembly, with his recent favorite, Rust . No, not all at the same time in the same application.
Anthony now spends his time building great teams, that leverage great technology, to build great products, but still looks to codes every chance he can get :)
An enhanced version of the #codemesh2014 talk on network programming in Go. It covers HTTP, HTTPS, TCP/IP, TCP/IP over TLS, UDP and basic cryptographic functions with AES-CBC and RSA.
How to Leverage Go for Your Networking NeedsDigitalOcean
Watch this Tech Talk: https://do.co/video_singuva
Highlights from Sneha Inguva’s networking journey through Go. Sneha discusses the useful packages, key learnings, and struggles faced while building a variety of networking services within and outside of DigitalOcean. Walk away with a clear understanding of how to specifically leverage Go for your own networking needs.
About the Presenter
Sneha Inguva is a Software Engineer on the Networking team at DigitalOcean. She enjoys building cloud products by day and debugging ominous context-canceled errors by night. In her spare time, she professionally lounges around with her cat.
New to DigitalOcean? Get US $100 in credit when you sign up: https://do.co/deploytoday
To learn more about DigitalOcean: https://www.digitalocean.com/
Follow us on Twitter: https://twitter.com/digitalocean
Like us on Facebook: https://www.facebook.com/DigitalOcean
Follow us on Instagram: https://www.instagram.com/thedigitalocean/
We're hiring: http://do.co/careers
An introduction into Googles programming language Go, which had its first release in March 2012. The talk has been held at the regulars' table of the GTUG Bremen.
Managing dependencies and third-party code in PHP applications is a daily challenge, keeping everyone on the same versions during development and at deploy time a struggle. Meet Composer a tool designed to help you maintain a consistent set of dependencies as well as share and discover new libraries. Let's see how you can use this tool in your Applications and Libraries to wrangle your dependencies with a simple json configuration file and a command line interface.
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...DynamicInfraDays
Slides from Rodric Rabbah & Philippe Suter's talk "OpenWhisk: A Serverless Computing Platform" at ContainerDays NYC 2016: dynamicinfradays.org/events/2016-nyc/programme.html#openwhisk
Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. AND IT'S TRUE!
In this talk given at JBCNConf 2015 in Barcelona, we will see how we use Netty at Trovit since 2013, what brought to us and how it opened our minds. We will share tips that helped us to learn more about Netty, some performance tricks and all things that worked for us.
So you're done developing your web service, but what will happen when you deploy it to production? In other words: how ready is your service to receive live traffic? In this talk you'll learn what it takes to transition your web service from "done" to "ready" and make sure that you can release to production seamlessly and with confidence.
The first cut of a talk on the R&D process in software development, including taking an invention to patent.
Includes two sets of code examples. One is Forth implemented in a 1980s dialect of Basic.
The other introduces evolutionary prototyping using a hybrid ruby/bash methodology.
Generics, Reflection, and Efficient CollectionsEleanor McHugh
This is a talk about how we structure and collate information so as to effectively process it, the language tools Go provides to help us do this, and the sometimes frustrating tradeoffs we must make when marry the real world with the digital.
We'll start by looking at basic collection types in Go: array, slice, map, and channel. These will then be used as the basis for our own user defined types with methods for processing the collected items.
These methods will then be expanded to take functions as parameters (the higher order functional style popularised by languages such as Ruby) and by using Go's Reflection package we will generalise them for a variety of tasks and uses cases.
Reflection adds an interpreted element to our programs with a resulting performance cost. Careful design can often minimise this cost and it may well amortise to zero on a sufficiently large collection however there is always greater code complexity to manage. When the data to be contained in a user defined collection is homogenous we can reduce much of this complexity by using Generics and our next set of examples will demonstrate this.
At the end of this talk you should have some useful ideas for designing your own collection types in Go as well as a reasonable base from which to explore Reflection, Generics, and the Higher-Order Functional style of programming.
An introduction to functional programming with goEleanor McHugh
A crash course in functional programming concepts using Go. Heavy on code, light on theory.
You can find the examples at https://github.com/feyeleanor/intro_to_fp_in_go
Implementing virtual machines in go & c 2018 reduxEleanor McHugh
An updated version of my talk on virtual machine cores comparing techniques in C and Go for implementing dispatch loops, stacks & hash maps.
Lots of tested and debugged code is provided as well as references to some useful/interesting books.
Digital Identity talk from Strange Loop 2018 and Build Stuff Lithuania 2018 including walkthrough of the uPass system and the design principles behind it.
Don't Ask, Don't Tell - The Virtues of Privacy By DesignEleanor McHugh
This is a fairly technical overview of the considerations involved in architecting software systems to support privacy. Rather than focus on what the law demands - something which can change across time and jurisdictions - it looks at the real problems we need to solve to know as little about the users of computer systems as possible whilst achieving their needs.
Don't ask, don't tell the virtues of privacy by designEleanor McHugh
A very light intro talk on privacy, identity, and designing with the latter to preserve the former.
Probably makes no sense at all without the audio so if it whet's your appetite dig through my other decks on these topics. Most of those have code in for the more technically minded.
An overview of the uPass digital identity system. Covers the core problem domain and the end-to-end stack from liveness to black-box transaction store. Lots of diagrams, references to all the relevant patent applications and so forth.
Finding a useful outlet for my many Adventures in goEleanor McHugh
A talk about my Leanpub-published living eBook: A Go Developer's Notebook. Buy my book? Write your own Book using Leanpub? Learn you some Golang for fun?
Implementing Software Machines in C and GoEleanor McHugh
The next iteration of the talk I gave at Progscon, this introduces examples of Map implementation (useful for caches etc.) and outlines for addition of processor core code in a later talk.
Implementing Software Machines in Go and CEleanor McHugh
Early draft of a tutorial on techniques for implementing virtual machines and language interpreters. Contains example programs for functional stacks and despatch loops.
This talk explores the importance of privacy in internet applications before introducing a range of practical ideas for enhancing their privacy and security.
A reworking of my 2010 RubyConf lightning talk introducing Go via a concurrent implementation of MapReduce. This code is probably buggy as hell and the design awful but it's also a reasonably good intro to the full breadth of Go.
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfJay Das
With the advent of artificial intelligence or AI tools, project management processes are undergoing a transformative shift. By using tools like ChatGPT, and Bard organizations can empower their leaders and managers to plan, execute, and monitor projects more effectively.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
Accelerate Enterprise Software Engineering with PlatformlessWSO2
Key takeaways:
Challenges of building platforms and the benefits of platformless.
Key principles of platformless, including API-first, cloud-native middleware, platform engineering, and developer experience.
How Choreo enables the platformless experience.
How key concepts like application architecture, domain-driven design, zero trust, and cell-based architecture are inherently a part of Choreo.
Demo of an end-to-end app built and deployed on Choreo.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
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
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
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
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
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
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
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
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
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
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
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
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