https://github.com/symphonyprotocol/p2p
Decentralized P2P networking framework
https://github.com/symphonyprotocol/p2p
cryptography golang network p2p
Last synced: 5 months ago
JSON representation
Decentralized P2P networking framework
- Host: GitHub
- URL: https://github.com/symphonyprotocol/p2p
- Owner: symphonyprotocol
- License: gpl-3.0
- Created: 2018-08-02T13:39:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-31T08:28:14.000Z (over 6 years ago)
- Last Synced: 2024-06-20T03:44:45.651Z (about 2 years ago)
- Topics: cryptography, golang, network, p2p
- Language: Go
- Size: 98.6 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# P2P
Decentralized P2P networking framework
## How to run example
### 1. Create a configuration file `~/.symchaincfg` in json format with the static nodes:
```json
{
"nodes":
[
{
"id": "c4ef0694fee0cdf78eab30c83b325293047e0b27511b92e8e206b199b24f13ea",
"ip":"101.200.156.243",
"port": 32768
}
]
}
```
> You can find the `id` in the console log when launching your application for now...
### 2. Start go file `examples/main.go` and it will connect to the static node and discover other nodes.
## How to use it in your application
```go
import (
"github.com/symphonyprotocol/p2p"
"github.com/symphonyprotocol/p2p/tcp"
"fmt"
)
type SampleMiddleware struct {}
func (s *SimpleMiddleware) Handle(ctx *tcp.P2PContext) {
fmt.Println("Handling message")
}
func (s *SimpleMiddleware) Start(ctx *tcp.P2PContext) {
fmt.Println("Middleware started")
}
func (s *SimpleMiddleware) AcceptConnection(conn *tcp.TCPConnection) {
fmt.Println("New connection got")
}
func (s *SimpleMiddleware) DropConnection(conn *tcp.TCPConnection) {
fmt.Println("Connection dropped")
}
func (s *SimpleMiddleware) Name() string { return "Sample Middleware" }
func (s *SimpleMiddleware) DashboardData() interface{} { return [][]string{ } }
func (s *SimpleMiddleware) DashboardType() string { return "table" }
func (s *SimpleMiddleware) DashboardTitle() string { return "Sample" }
func (s *SimpleMiddleware) DashboardTableHasColumnTitles() bool { return false }
func main() {
server := p2p.NewP2PServer()
server.Use(&SimpleMiddleware{})
}
```
## Module Support
* In progress