package
0.10.2
Repository: https://github.com/sigcn/pg.git
Documentation: pkg.go.dev

# README

p2p library

Example

Peer1 (act as echo server)

serverURL := "wss://synf.in/pg"

intent, err := network.JoinOIDC(oidc.ProviderGoogle, peermapURL)
if err != nil {
    panic(err)
}
fmt.Println(intent.AuthURL()) // https://synf.in/oidc/google?state=5G68CtYnMRMdrtrRF
networkSecret, err := intent.Wait(context.TODO())
if err != nil {
    panic(err)
}

// peerID is a unique string (less than 256bytes)
packetConn, err := p2p.ListenPacket(disco.NewServer(serverURL, networkSecret), p2p.ListenPeerID("uniqueString"))
if err != nil {
    panic(err)
}

// unreliability echo server
buf := make([]byte, 1024)
for {
    n, peerID, err := packetConn.ReadFrom(buf)
    if err != nil {
        panic(err)
    }
    fmt.Println("Echo packet to", peerID, string(buf[:n]))
    _, err = packetConn.WriteTo(peerID, buf[:n])
    if err != nil {
        panic(err)
    }
}

Peer2

...

packetConn, err := p2p.ListenPacket(disco.NewServer(serverURL, networkSecret))
if err != nil {
    panic(err)
}

defer packetConn.Close()

// "uniqueString" is above echo server's address
_, err := packetConn.WriteTo(peer.ID("uniqueString"), []byte("hello"))
if err != nil {
    panic(err)
}

packetConn.SetReadDeadline(time.Now().Add(time.Second))

buf := make([]byte, 1024)
n, peerID, err := packetConn.ReadFrom(buf)
if err !=nil {
    panic(err)
}
fmt.Println(peerID, ":", string(buf[:n])) // uniqueString : hello

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ListenPacket same as ListenPacketContext, but no context required.
ListenPacketContext listen the p2p network for read/write packets.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author