Skip to content

geolffreym/p2p-noise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

P2P Noise

Go Go Reference Go Report Card codecov

P2P Noise library aims to serve as a tool to create secure P2P networks based on the Noise Framework.

Features

Noise Secure Handshake: Noise is a framework for building crypto protocols. Noise protocols support mutual and optional authentication, identity hiding, forward secrecy, zero round-trip encryption, and other advanced features.

Adaptive Lookup for Unstructured Peer-to-Peer Overlays: Most of the unstructured peer-to-peer overlays do not provide any performance guarantee. "Adaptive Lookup" propose a novel Quality of Service enabled lookup for unstructured peer-to-peer overlays that will allow the user’s query to traverse only those overlay links which satisfy the given constraints.

Install

go get github.com/geolffreym/p2p-noise

Basic usage


import (
	noise "github.com/geolffreym/p2p-noise"
	"github.com/geolffreym/p2p-noise/config"
)

func main() {

	// Create configuration from params and write in configuration reference
	configuration := config.New()
	configuration.Write(
		config.SetMaxPeersConnected(10),
		config.SetPeerDeadline(1800),
	)

	// Node factory
	node := noise.New(configuration)
	// Network events channel
	signals, cancel := node.Signals()

	go func() {
		for signal := range signals {
			// Here could be handled events
			if signal.Type() == noise.NewPeerDetected {
				cancel()
			}
		}
	}()

	// ... some code here
	// node.Dial("192.168.1.1:4008")
	// node.Close()

	// ... more code here
	node.Listen()

}

Benchmarking

Handshake Benchmark

Using perflock to prevent our benchmarks from using too much CPU at once.

perflock -governor=80% go test -benchmem -run=^$ -benchtime 1s -bench=. -cpu 1,2,4,8 -count=1
goos: linux
goarch: amd64
pkg: github.com/geolffreym/p2p-noise
cpu: Intel(R) Xeon(R) CPU E3-1505M v5 @ 2.80GHz
BenchmarkHandshakeProfile                            726           1575256 ns/op           46959 B/op        363 allocs/op
BenchmarkHandshakeProfile-2                         1548           1037351 ns/op           47100 B/op        364 allocs/op
BenchmarkHandshakeProfile-4                         2460            908573 ns/op           49885 B/op        383 allocs/op
BenchmarkHandshakeProfile-8                         2127            736442 ns/op           60454 B/op        457 allocs/op
BenchmarkNodesSecureMessageExchange             29032570                35.03 ns/op            0 B/op          0 allocs/op
BenchmarkNodesSecureMessageExchange-2           59745247                16.78 ns/op            0 B/op          0 allocs/op
BenchmarkNodesSecureMessageExchange-4           124446950                9.454 ns/op           0 B/op          0 allocs/op
BenchmarkNodesSecureMessageExchange-8           151214516                7.088 ns/op           0 B/op          0 allocs/op
PASS
ok      github.com/geolffreym/p2p-noise 18.865s

Development

Some available capabilities for dev support:

  • Run Tests: make test
  • Build: make build
  • Test Coverage: make coverage
  • Benchmark: make benchmark
  • Profiling: make profiling
  • Code check: make check
  • Code format: make format
  • Flush cache: make clean
  • Build: make build

Note: Run make help to check for more capabilities.

More info

About

Peer to Peer Library based on Noise Secure Handshake

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published