package client
import (
"context"
"io"
"sync"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/transport"
"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto"
logging "github.com/ipfs/go-log/v2"
)
var log = logging .Logger ("p2p-circuit" )
type Client struct {
ctx context .Context
ctxCancel context .CancelFunc
host host .Host
upgrader transport .Upgrader
incoming chan accept
mx sync .Mutex
activeDials map [peer .ID ]*completion
hopCount map [peer .ID ]int
}
var _ io .Closer = &Client {}
var _ transport .Transport = &Client {}
type accept struct {
conn *Conn
writeResponse func () error
}
type completion struct {
ch chan struct {}
relay peer .ID
err error
}
func New (h host .Host , upgrader transport .Upgrader ) (*Client , error ) {
cl := &Client {
host : h ,
upgrader : upgrader ,
incoming : make (chan accept ),
activeDials : make (map [peer .ID ]*completion ),
hopCount : make (map [peer .ID ]int ),
}
cl .ctx , cl .ctxCancel = context .WithCancel (context .Background ())
return cl , nil
}
func (c *Client ) Start () {
c .host .SetStreamHandler (proto .ProtoIDv2Stop , c .handleStreamV2 )
}
func (c *Client ) Close () error {
c .ctxCancel ()
c .host .RemoveStreamHandler (proto .ProtoIDv2Stop )
return nil
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .