Documentation
¶
Overview ¶
Package p2phttp implements Raminga HTTP over libp2p streams using net/http and gostream. It deliberately does not use the experimental p2p/http package.
Index ¶
- Constants
- Variables
- func IsProtocolUnsupported(err error) bool
- func PeerID(ctx context.Context) (peer.ID, bool)
- func ProtocolMismatch(err error, proto protocol.ID) error
- func WithPeerID(ctx context.Context, pid peer.ID) context.Context
- type Client
- func (c *Client) Close()
- func (c *Client) Dial(ctx context.Context, pid peer.ID) error
- func (c *Client) Do(ctx context.Context, pid peer.ID, req *http.Request, maxBody int64) (*Result, error)
- func (c *Client) DoWithDial(ctx context.Context, pid peer.ID, req *http.Request, maxBody int64) (*Result, error)
- func (c *Client) SetDial(dial func(context.Context, peer.ID) error)
- type ClientOptions
- type Options
- type ProtocolUnsupportedError
- type Result
- type Server
Constants ¶
const ( // ProtocolID is the single Raminga HTTP-over-libp2p protocol. ProtocolID = protocol.ID("/raminga/http/1.0.0") DefaultReadHeaderTimeout = 10 * time.Second DefaultReadTimeout = 30 * time.Second DefaultIdleTimeout = 60 * time.Second DefaultMaxHeaderBytes = 16 << 10 DefaultMaxBodyBytes = 1 << 20 DefaultPerPeerRate = 5 DefaultPerPeerBurst = 10 DefaultMaxTrackedPeers = 1024 DefaultPerPeerConcurrent = 4 DefaultGlobalConcurrent = 64 )
Variables ¶
var ( ErrResponseTooLarge = errors.New("p2phttp: response body exceeds limit") ErrNoDialFunc = errors.New("p2phttp: no dial helper configured") )
Functions ¶
func IsProtocolUnsupported ¶
IsProtocolUnsupported detects multistream.ErrNotSupported through the net/http transport's *url.Error wrapping instead of matching error strings.
func ProtocolMismatch ¶
ProtocolMismatch converts an unsupported-protocol dial error into the user-facing version-incompatibility message and leaves other errors alone.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) DoWithDial ¶
type ClientOptions ¶
type ClientOptions struct {
MaxResponseHeaderBytes int64
DefaultBodyLimit int64
Dial func(context.Context, peer.ID) error
}
func DefaultClientOptions ¶
func DefaultClientOptions() ClientOptions
type Options ¶
type Options struct {
ReadHeaderTimeout time.Duration
ReadTimeout time.Duration
IdleTimeout time.Duration
MaxHeaderBytes int
MaxBodyBytes int64
PerPeerRate float64
PerPeerBurst int
MaxTrackedPeers int
PerPeerConcurrent int
GlobalConcurrent int
// DisableRateLimit lets a route (e.g. chat with dedupe-before-rate) own
// its per-peer budget instead of applying the generic HTTP limiter.
DisableRateLimit bool
}
Options configures the server. Per-route long downloads should use http.NewResponseController to set their own write deadline; the server leaves WriteTimeout at zero so a global write timeout cannot kill downloads.
func DefaultOptions ¶
func DefaultOptions() Options
type ProtocolUnsupportedError ¶
ProtocolUnsupportedError reports that the remote multistream muxer does not offer the Raminga HTTP protocol. Wrapping keeps the original dial error available through errors.Is/errors.As.
func (*ProtocolUnsupportedError) Error ¶
func (e *ProtocolUnsupportedError) Error() string
func (*ProtocolUnsupportedError) Unwrap ¶
func (e *ProtocolUnsupportedError) Unwrap() error
type Server ¶
type Server struct {
// contains filtered or unexported fields
}