GO2P is a P2P framework, designed with flexibility and simplicity in mind

Overview

go2p

golang p2p framework

By v-braun - viktor-braun.de.

Build Status codecov Go Report Card Documentation PR welcome

Description

GO2P is a P2P framework, designed with flexibility and simplicity in mind. You can use a pre configured stack (encryption, compression, etc.) or built your own based on the existing modules.

GO2P use the middleware pattern as a core pattern for messages. If you have used expressJS, OWIN or other HTTP/Web based frameworks you should be familiar with that.
The basic idea is that an outgoing message is passed through multiple middleware functions. Each of this functions can manipulate the message.
A middleware function could encrypt, compress, log or sign the message.
Outgoing messages will be processed through the middleware functions and incomming messages in the inverted order:

Installation

go get github.com/v-braun/go2p

Usage

You like code? Checkout the chat example

The simplest way to use this framework is to create a new instance of the full configured TCP based network stack:

    localAddr := "localhost:7077"
	net := go2p.NewNetworkConnectionTCP(*localAddr, &map[string]func(peer *go2p.Peer, msg *go2p.Message){
		"msg": func(peer *go2p.Peer, msg *go2p.Message) {
			fmt.Printf("%s > %s\n", peer.RemoteAddress(), msg.PayloadGetString())
		},
    })
    
    net.OnPeer(func(p *go2p.Peer) {
		fmt.Printf("new peer: %s\n", p.RemoteAddress())
    })
    
    err := net.Start()
	if err != nil {
		panic(err)
    }

    defer net.Stop()
    

    // connects to another peer via tcp
    net.ConnectTo("tcp", "localhost:7077")

    // send a message to the 'msg' route 
    net.SendBroadcast(go2p.NewMessageRoutedFromString("msg", "hello go2p"))

Advanced Usage

The function NewNetworkConnectionTCP is a shorthand for the advanced configuration of a network stack.

	op := go2p.NewTCPOperator("tcp", localAddr) // creates a tcp based operator (net.Dialer and net.Listener)
	peerStore := go2p.NewDefaultPeerStore(10) // creates a simple peer store that limits connections to 10

	conn := go2p.NewNetworkConnection(). // creates a new instance of the builder
		WithOperator(op). // adds the operator to the network stack
		WithPeerStore(peerStore). // adds the peer store to the network stack
		WithMiddleware(go2p.Routes(routes)). // adds the routes middleware
		WithMiddleware(go2p.Headers()). // adds the headers middleware
		WithMiddleware(go2p.Crypt()). // adds encryption
		WithMiddleware(go2p.Log()). // adds logging
		Build() // creates the network 

This code creates a new NetworkConnection that use tcp communication, a default PeerStore and some middlewares.
Outgoing messages will now pass the following middlewares:

(app logic) -> Routing -> Headers -> Crypt -> Log -> (network) 

Incomming messages will pass the following middlewares

(app logic) <- Routing <- Headers <- Crypt <- Log <- (network)

Authors

image
v-braun

Contributing

Make sure to read these guides before getting started:

License

go2p is available under the MIT License. See LICENSE for details.

Issues
  • [QUESTION] Peers address

    [QUESTION] Peers address

    Hello,

    How are generated peers address?

    For example, with https://github.com/v-braun/go2p/blob/master/example_test.go If I run a server at 127.0.0.1:7071 and another one at 127.0.0.1:7072 for example and I connect it to the first one, the peer address change to something like 127.0.0.1:30002

    Probably a stupid question, but I'm a Junior (especially in P2P ... ) Thanks :)

    opened by Icesofty 1
  • panic: runtime error: slice bounds out of range

    panic: runtime error: slice bounds out of range

    Hi :) I have an issue when I try to send a message from a server (Terminal 1) to more than one client (Terminal 2 and 3)

    Problem Description:

    panic: runtime error: slice bounds out of range [:535024639] with capacity 359
    
    goroutine 36 [running]:
    github.com/v-braun/go2p.middlewareHeadersImpl(0xc00040c000, 0xc00040c0a0, 0xc000050080, 0x1, 0x1, 0x0)
            C:/Users/argau/go/src/github.com/v-braun/go2p/middleware_headers.go:57 +0x45b
    github.com/v-braun/go2p.(*Pipe).process(0xc00040c0a0, 0xc000050080, 0x4, 0x4)   
            C:/Users/argau/go/src/github.com/v-braun/go2p/pipe.go:63 +0x3b0
    github.com/v-braun/go2p.(*Peer).processPipe(0xc00040c000, 0xc000050080, 0x1)    
            C:/Users/argau/go/src/github.com/v-braun/go2p/peer.go:71 +0x93
    github.com/v-braun/go2p.(*Peer).start.func3()
            C:/Users/argau/go/src/github.com/v-braun/go2p/peer.go:48 +0x1a7
    github.com/v-braun/awaiter.(*awaiter).Go.func1(0xc00040e0e0, 0xc00040e020)      
            C:/Users/argau/go/src/github.com/v-braun/awaiter/awaiter.go:51 +0x59    
    created by github.com/v-braun/awaiter.(*awaiter).Go
            C:/Users/argau/go/src/github.com/v-braun/awaiter/awaiter.go:49 +0x6a    
    exit status 2
    
    package main
    
    import (
    	"bufio"
    	"flag"
    	"fmt"
    	"os"
    	"strings"
    
    	"github.com/fatih/color"
    	"github.com/sirupsen/logrus"
    	"github.com/v-braun/go2p"
    	prefixed "github.com/x-cray/logrus-prefixed-formatter"
    )
    
    func main() {
    	logrus.SetFormatter(new(prefixed.TextFormatter))
    	logrus.SetOutput(os.Stdout)
    	logrus.SetLevel(logrus.DebugLevel)
    
    	/* 	localHost := "localhost:7071"
    	 */
    	localAddr := flag.String("laddr", "localhost:7071", "local ip address")
    	flag.Parse()
    
    	cyan := color.New(color.FgCyan).SprintFunc()
    	blue := color.New(color.FgHiBlue).SprintFunc()
    	green := color.New(color.FgHiGreen).SprintFunc()
    	white := color.New(color.FgHiWhite).SprintFunc()
    	peerName := color.New(color.BgBlue, color.FgHiWhite).SprintFunc()
    
    	/* 	if localHost == "localhost:7071" {
    	   		peerName = color.New(color.BgHiMagenta, color.FgHiWhite).SprintFunc()
    	   	} else if localHost == "localhost:7072" {
    	   		peerName = color.New(color.BgHiYellow, color.FgHiWhite).SprintFunc()
    	   	} */
    
    	net := go2p.NewNetworkConnectionTCP(*localAddr, &map[string]func(peer *go2p.Peer, msg *go2p.Message){
    		"msg": func(peer *go2p.Peer, msg *go2p.Message) {
    			fmt.Println(fmt.Sprintf("%s %s", peerName(peer.RemoteAddress()+" > "), msg.PayloadGetString()))
    		},
    	})
    
    	err := net.Start()
    	if err != nil {
    		panic(err)
    	}
    
    	net.OnPeer(func(p *go2p.Peer) {
    		fmt.Printf("%s %s\n", cyan("new peer:"), green(p.RemoteAddress()))
    	})
    
    	defer net.Stop()
    
    	fmt.Println(cyan(`
    local server started!
    press:
    	`))
    
    	fmt.Printf("%s %s\n", blue("[q][ENTER]"), white("to exit"))
    	fmt.Printf("%s %s\n", blue("[c {ip address : port}][ENTER]"), white("to connect to another peer"))
    	fmt.Printf("%s %s\n", blue("[any message][ENTER]"), white("to send a message to all peers"))
    
    	reader := bufio.NewReader(os.Stdin)
    	for {
    		text, _ := reader.ReadString('\n')
    		text = strings.TrimSpace(text)
    		if text == "q" {
    			return
    		} else if strings.HasPrefix(text, "c ") {
    			text = strings.TrimPrefix(text, "c ")
    			net.ConnectTo("tcp", text)
    		} else {
    			net.SendBroadcast(go2p.NewMessageRoutedFromString("msg", text))
    		}
    	}
    }
    

    First Terminal go run main.go Second Terminal go run main.go -laddr=localhost:7072 c localhost:7071 Third Terminal go run main.go -laddr=localhost:7073 c localhost:7071

    First Terminal Send A Message

    Second or Third Terminal will panic

    Environment:

    • Windows 10
    • Latest Verison of Go2p
    opened by Icesofty 2
Owner
Viktor Braun
Viktor Braun
fetch and serve papers in p2p network

sci-hub P2P A project aims to fetch paper from the BitTorrent network. This is not a cli client of sci-hub website. English Introduction 中文简介 Contribu

Sci-Hub on P2P 181 Jun 17, 2022
Openp2p - an open source, free, and lightweight P2P sharing network

It is an open source, free, and lightweight P2P sharing network. As long as any device joins in, you can access them anywhere

null 47 Jun 20, 2022
Staex GmbH 12 Jun 20, 2022
Goph - A lightweight Go SSH client focusing on simplicity

Golang SSH Client. Fast and easy golang ssh client module. Goph is a lightweight

Serialt 0 May 26, 2022
A decentralized P2P networking stack written in Go.

noise noise is an opinionated, easy-to-use P2P network stack for decentralized applications, and cryptographic protocols written in Go. noise is made

Perlin Network 1.7k Jun 22, 2022
A major platform Remote Access Terminal Tool based by Blockchain/P2P.

NGLite A major platform Remote Access Terminal Tool based by Blockchain/P2P. No public IP address required.More anonymity Example Detection Warning!!!

null 258 Jun 26, 2022
fetch papers from p2p network

sci-hub P2P A project aims to fetch paper from the BitTorrent network. According to this Reddit post, currently, all `sci-hub's papers are available i

Trim21 181 Jun 17, 2022
A modular is an opinionated, easy-to-use P2P network stack for decentralized applications written in Go.

xlibp2p xlibp2p is an opinionated, easy-to-use P2P network stack for decentralized applications written in Go. xlibp2p is made to be minimal, robust,

XFS Network 62 Jun 7, 2022
A minimal IPFS replacement for P2P IPLD apps

IPFS-Nucleus IPFS-Nucleus is a minimal block daemon for IPLD based services. You could call it an IPLDaemon. It implements the following http api call

Peergos 19 Jun 12, 2022
Educational project to build a p2p network

Template go Repository tl;dr This is a template go repository with actions already set up to create compiled releases What does this Template provide?

Marco Siebecke 0 Dec 2, 2021
P2P Forwarder - a tool for farwarding tcp/udp ports. Made using libp2p.

P2P Forwarder A tool for farwarding ports. Made using libp2p. How it works A: opens desired ports ports inside P2P Forwarder A: shares it's id from P2

null 23 Jan 14, 2022
Xlibp2p: an opinionated, easy-to-use P2P network stack for decentralized applications written in Go

xlibp2p xlibp2p is an opinionated, easy-to-use P2P network stack for decentraliz

null 2 Feb 21, 2022
Steve - A peer-to-peer (p2p) decentralized network

Steve Steve is a peer-to-peer (p2p) decentralized network that enables people to

Steve Care Software Inc 4 Feb 5, 2022
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.

Fast passive subdomain enumeration tool. Features • Install • Usage • API Setup • License • Join Discord Subfinder is a subdomain discovery tool that

ProjectDiscovery 5.7k Jun 23, 2022
TFTP and HTTP server specifically designed to serve iPXE ROMs and scripts.

pixie TFTP and HTTP server specifically designed to serve iPXE ROMs and scripts. pixie comes embedded with the following ROMs provided by the iPXE pro

Adrian L Lange 13 Jun 27, 2022
httpx is a fast and multi-purpose HTTP toolkit allows to run multiple probers using retryablehttp library, it is designed to maintain the result reliability with increased threads.

Features • Installation • Usage • Running httpx • Notes • Join Discord httpx is a fast and multi-purpose HTTP toolkit allow to run multiple probers us

ProjectDiscovery 3.3k Jun 25, 2022
O365 is a tool designed to perform user enumeration* and password guessing attacks on organizations that use Office365

O365 is a tool designed to perform user enumeration* and password guessing attacks on organizations that use Office365 (now/soon Microsoft365). O365 uses a unique SOAP API endpoint on login.microsoftonline.com that most other tools do not use.

Trewis [work] Scotch 3 Jun 2, 2022
Echo-server - An HTTP echo server designed for testing applications and proxies

echo-server An HTTP echo server designed for testing applications and proxies. R

Erik Cavalcanti 4 Jan 5, 2022
Simple HTTP/HTTPS proxy - designed to be distributed as a self-contained binary that can be dropped in anywhere and run.

Simple Proxy This is a simple HTTP/HTTPS proxy - designed to be distributed as a self-contained binary that can be dropped in anywhere and run. Code b

Jamie Thompson 13 May 9, 2022