Documentation
¶
Overview ¶
Package noise provides a high-level net.Conn/net.Listener/net.Addr wrapper around the Noise Protocol Framework. This file re-exports the public API from the noise/conn, noise/listener, and noise/shutdown sub-packages so that callers continue to use the root import path unchanged.
Index ¶
- Constants
- func GetGlobalConnPool() pool.Pooldeprecated
- func GracefulShutdown() errordeprecated
- func ResetDefault()
- func SetGlobalConnPool(p pool.Pool)deprecated
- func SetGlobalShutdownManager(sm Shutdowner)deprecated
- func ValidateHandshakePattern(pattern string) error
- type ConnConfig
- type ConnState
- type ListenerConfig
- type NoiseAddr
- type NoiseConn
- func DialNoise(network, addr string, config *ConnConfig) (*NoiseConn, error)deprecated
- func DialNoiseWithHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)deprecated
- func DialNoiseWithHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)deprecated
- func DialNoiseWithPool(network, addr string, config *ConnConfig) (*NoiseConn, error)deprecated
- func DialNoiseWithPoolAndHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)deprecated
- func DialNoiseWithPoolAndHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)deprecated
- func NewNoiseConn(underlying net.Conn, config *ConnConfig) (*NoiseConn, error)
- func WrapConn(conn net.Conn, config *ConnConfig) (*NoiseConn, error)
- type NoiseConnIface
- type NoiseListener
- type NoiseListenerIface
- type ShutdownConn
- type ShutdownListener
- type ShutdownManager
- type Shutdowner
- type Transport
- func (t *Transport) Dial(network, addr string, config *ConnConfig) (*NoiseConn, error)
- func (t *Transport) DialWithHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)
- func (t *Transport) DialWithHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)
- func (t *Transport) DialWithPool(network, addr string, config *ConnConfig) (*NoiseConn, error)
- func (t *Transport) DialWithPoolAndHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)
- func (t *Transport) DialWithPoolAndHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)
- func (t *Transport) GracefulShutdown() error
- func (t *Transport) Listen(network, addr string, config *ListenerConfig) (*NoiseListener, error)
Constants ¶
const ( StateInit = conn.StateInit StateHandshaking = conn.StateHandshaking StateEstablished = conn.StateEstablished StateClosed = conn.StateClosed )
Connection state constants forwarded from noise/conn for backwards compatibility.
Variables ¶
This section is empty.
Functions ¶
func GetGlobalConnPool
deprecated
func GracefulShutdown
deprecated
func GracefulShutdown() error
GracefulShutdown initiates graceful shutdown of all Default Transport components.
Deprecated: Use Transport.GracefulShutdown on a dedicated Transport instance instead.
func ResetDefault ¶ added in v0.1.56
func ResetDefault()
ResetDefault resets the package-level Default Transport and its initialisation state so that the next call to getDefault() creates a fresh instance.
Intended for test isolation only. Do not call in production code; concurrent callers that hold a reference to the previous Default will observe a stale pointer.
If a Default Transport exists, ResetDefault calls GracefulShutdown on it to clean up pool resources and shutdown manager goroutines before dropping the reference. This prevents goroutine leaks in test suites that call ResetDefault multiple times.
func SetGlobalConnPool
deprecated
SetGlobalConnPool sets a custom connection pool on the Default Transport. p may be any implementation of pool.Pool, including *pool.ConnPool.
Deprecated: Use Transport.DialWithPool or Transport.DialWithPoolAndHandshake on a dedicated Transport instance instead of mutating global state.
func SetGlobalShutdownManager
deprecated
func SetGlobalShutdownManager(sm Shutdowner)
SetGlobalShutdownManager sets a custom shutdown manager on the Default Transport. The previous shutdown manager is shut down gracefully before being replaced.
Deprecated: Use a dedicated Transport instance instead of mutating global state.
func ValidateHandshakePattern ¶ added in v0.1.56
ValidateHandshakePattern reports whether pattern is a known Noise handshake pattern name, accepting short ("XX") and full protocol names.
Types ¶
type ConnConfig ¶
type ConnConfig = conn.ConnConfig
ConnConfig is an alias for conn.ConnConfig.
func NewConnConfig ¶
func NewConnConfig(pattern string, initiator bool) *ConnConfig
NewConnConfig creates a ConnConfig with sensible defaults.
type ListenerConfig ¶
type ListenerConfig = listener.ListenerConfig
ListenerConfig is an alias for listener.ListenerConfig.
func NewListenerConfig ¶
func NewListenerConfig(pattern string) *ListenerConfig
NewListenerConfig creates a ListenerConfig with sensible defaults.
type NoiseConn ¶
NoiseConn is an alias for conn.Conn.
func DialNoise
deprecated
func DialNoise(network, addr string, config *ConnConfig) (*NoiseConn, error)
DialNoise creates a connection to the given address and wraps it with NoiseConn. This is a convenience function that delegates to the Default Transport.
Deprecated: Use Transport.Dial on a dedicated Transport instance instead of depending on package-level global state.
func DialNoiseWithHandshake
deprecated
func DialNoiseWithHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)
DialNoiseWithHandshake creates a connection to the given address, wraps it with NoiseConn, and performs the handshake with retry logic. This is the recommended high-level function for establishing Noise connections with automatic retry capabilities.
Deprecated: Use Transport.DialWithHandshake on a dedicated Transport instance instead of depending on package-level global state.
func DialNoiseWithHandshakeContext
deprecated
func DialNoiseWithHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)
DialNoiseWithHandshakeContext creates a connection with context support for cancellation. It combines dialing, NoiseConn creation, and handshake with retry in a single operation.
Deprecated: Use Transport.DialWithHandshakeContext on a dedicated Transport instance instead of depending on package-level global state.
func DialNoiseWithPool
deprecated
func DialNoiseWithPool(network, addr string, config *ConnConfig) (*NoiseConn, error)
DialNoiseWithPool creates a connection to the given address, checking the pool first. If a suitable connection is available in the pool, it will be reused. Otherwise, a new connection is created. The connection will be automatically returned to the pool when the NoiseConn is closed.
Deprecated: Use Transport.DialWithPool on a dedicated Transport instance instead of depending on package-level global state.
func DialNoiseWithPoolAndHandshake
deprecated
func DialNoiseWithPoolAndHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)
DialNoiseWithPoolAndHandshake creates a connection with pool support and handshake retry. It checks the pool first, creates new if needed, and performs handshake with retry logic.
Deprecated: Use Transport.DialWithPoolAndHandshake on a dedicated Transport instance instead of depending on package-level global state.
func DialNoiseWithPoolAndHandshakeContext
deprecated
func DialNoiseWithPoolAndHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)
DialNoiseWithPoolAndHandshakeContext combines pool checking, dialing, and handshake with context. It reuses a pooled raw TCP connection when available (the pool keys by conn.RemoteAddr().String(), which equals addr), wraps it in a new NoiseConn, and performs the Noise handshake. Falls back to a fresh dial if the pool is empty or the pooled connection fails the handshake.
Deprecated: Use Transport.DialWithPoolAndHandshakeContext on a dedicated Transport instance instead of depending on package-level global state.
func NewNoiseConn ¶
func NewNoiseConn(underlying net.Conn, config *ConnConfig) (*NoiseConn, error)
NewNoiseConn creates a new NoiseConn wrapping the given net.Conn.
type NoiseConnIface ¶ added in v0.1.56
NoiseConnIface is an alias for conn.ConnIface. Use this interface instead of *NoiseConn when you need to substitute test doubles or alternative implementations.
type NoiseListener ¶
NoiseListener is an alias for listener.Listener.
func ListenNoise
deprecated
func ListenNoise(network, addr string, config *ListenerConfig) (*NoiseListener, error)
ListenNoise creates a listener on the given address and wraps it with NoiseListener. This is a convenience function that delegates to the Default Transport.
Deprecated: Use Transport.Listen on a dedicated Transport instance instead of depending on package-level global state.
func NewNoiseListener ¶
func NewNoiseListener(underlying net.Listener, config *ListenerConfig) (*NoiseListener, error)
NewNoiseListener wraps an existing net.Listener with Noise Protocol encryption.
func WrapListener ¶
func WrapListener(listener net.Listener, config *ListenerConfig) (*NoiseListener, error)
WrapListener wraps an existing net.Listener with NoiseListener. This is an alias for NewNoiseListener for consistency with the transport API.
type NoiseListenerIface ¶ added in v0.1.56
type NoiseListenerIface = listener.ListenerIface
NoiseListenerIface is an alias for listener.ListenerIface. Use this interface instead of *NoiseListener when you need to substitute test doubles or alternative implementations.
type ShutdownConn ¶ added in v0.1.56
type ShutdownConn = shutdown.ShutdownConn
ShutdownConn is an alias for shutdown.ShutdownConn.
type ShutdownListener ¶ added in v0.1.56
type ShutdownListener = shutdown.ShutdownListener
ShutdownListener is an alias for shutdown.ShutdownListener.
type ShutdownManager ¶
type ShutdownManager = shutdown.ShutdownManager
ShutdownManager is an alias for shutdown.ShutdownManager.
func NewShutdownManager ¶
func NewShutdownManager(timeout time.Duration) *ShutdownManager
NewShutdownManager creates a ShutdownManager with the given graceful-shutdown timeout.
type Shutdowner ¶ added in v0.1.56
type Shutdowner = shutdown.Shutdowner
Shutdowner is an alias for shutdown.Shutdowner. Accept Shutdowner instead of *ShutdownManager to allow substitution of test doubles or alternative shutdown coordinators.
func GetGlobalShutdownManager
deprecated
func GetGlobalShutdownManager() Shutdowner
GetGlobalShutdownManager returns the Default Transport's shutdown manager.
Deprecated: Use a dedicated Transport instance instead of accessing global state.
type Transport ¶ added in v0.1.56
type Transport struct {
// contains filtered or unexported fields
}
Transport owns a Pool and ShutdownManager and provides Dial/Listen methods. Construct one with NewTransport; use the package-level Default for the conventional singleton.
var Default *Transport
Default is the package-level Transport used by DialNoise, ListenNoise, etc. It is lazily initialised on first use via getDefault().
Deprecated: Package-level convenience only. Callers that share the Default instance across goroutines or tests affect shared state (pool, shutdown manager). Prefer constructing a Transport directly for production use:
newTransport := noise.NewTransport(myPool, myShutdown)
For test isolation, call ResetDefault() in your TestMain or test teardown.
func NewTransport ¶ added in v0.1.56
func NewTransport(p pool.Pool, sm Shutdowner) *Transport
NewTransport creates a Transport backed by the given pool and shutdown manager. Either may be nil: a nil pool disables connection reuse; a nil ShutdownManager disables shutdown registration.
func (*Transport) Dial ¶ added in v0.1.56
func (t *Transport) Dial(network, addr string, config *ConnConfig) (*NoiseConn, error)
Dial creates a Noise-wrapped connection to the given address using this Transport's ShutdownManager and Pool. It is the Transport-scoped equivalent of DialNoise.
func (*Transport) DialWithHandshake ¶ added in v0.1.56
func (t *Transport) DialWithHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)
DialWithHandshake creates a connection to the given address, wraps it with NoiseConn, and performs the handshake with retry logic.
func (*Transport) DialWithHandshakeContext ¶ added in v0.1.56
func (t *Transport) DialWithHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)
DialWithHandshakeContext creates a connection with context support for cancellation. It combines dialing, NoiseConn creation, and handshake with retry in a single operation.
func (*Transport) DialWithPool ¶ added in v0.1.56
func (t *Transport) DialWithPool(network, addr string, config *ConnConfig) (*NoiseConn, error)
DialWithPool creates a connection to the given address, checking this Transport's pool first. If a suitable connection is available in the pool, it will be reused. Otherwise, a new connection is created. The connection will be automatically returned to the pool when the NoiseConn is closed.
func (*Transport) DialWithPoolAndHandshake ¶ added in v0.1.56
func (t *Transport) DialWithPoolAndHandshake(network, addr string, config *ConnConfig) (*NoiseConn, error)
DialWithPoolAndHandshake creates a connection with pool support and handshake retry. It checks the pool first, creates new if needed, and performs handshake with retry logic.
func (*Transport) DialWithPoolAndHandshakeContext ¶ added in v0.1.56
func (t *Transport) DialWithPoolAndHandshakeContext(ctx context.Context, network, addr string, config *ConnConfig) (*NoiseConn, error)
DialWithPoolAndHandshakeContext combines pool checking, dialing, and handshake with context. It reuses a pooled raw TCP connection when available (the pool keys by conn.RemoteAddr().String(), which equals addr), wraps it in a new NoiseConn, and performs the Noise handshake. Falls back to a fresh dial if the pool is empty or the pooled connection fails the handshake.
func (*Transport) GracefulShutdown ¶ added in v0.1.56
GracefulShutdown shuts down this Transport's ShutdownManager and Pool.
func (*Transport) Listen ¶ added in v0.1.56
func (t *Transport) Listen(network, addr string, config *ListenerConfig) (*NoiseListener, error)
Listen creates a Noise-wrapped listener on the given address using this Transport's ShutdownManager. It is the Transport-scoped equivalent of ListenNoise.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package noise provides a high-level wrapper around the go-i2p/noise package implementing net.Conn, net.Listener, and net.Addr interfaces for the Noise Protocol Framework.
|
Package noise provides a high-level wrapper around the go-i2p/noise package implementing net.Conn, net.Listener, and net.Addr interfaces for the Noise Protocol Framework. |
|
examples
|
|
|
basic
command
Example: Basic usage of the go-noise library with configurable patterns and complete handshakes
|
Example: Basic usage of the go-noise library with configurable patterns and complete handshakes |
|
comprehensive-patterns
command
|
|
|
echoclient
command
Example: Echo Client using Noise Protocol with complete handshake
|
Example: Echo Client using Noise Protocol with complete handshake |
|
echoserver
command
Example: Echo Server using Noise Protocol with complete handshake
|
Example: Echo Server using Noise Protocol with complete handshake |
|
exampleutil
Package exampleutil provides common utilities for go-noise examples
|
Package exampleutil provides common utilities for go-noise examples |
|
listener
command
Example: NoiseListener demonstration with complete handshake
|
Example: NoiseListener demonstration with complete handshake |
|
modifiers
command
|
|
|
ntcp2
command
Example: NTCP2 addressing and connection demonstration for I2P router addressing
|
Example: NTCP2 addressing and connection demonstration for I2P router addressing |
|
ntcp2-config
command
Example: NTCP2Config builder pattern demonstration for I2P transport configuration This example shows how to create and configure NTCP2Config objects using the builder pattern with proper argument handling and validation.
|
Example: NTCP2Config builder pattern demonstration for I2P transport configuration This example shows how to create and configure NTCP2Config objects using the builder pattern with proper argument handling and validation. |
|
ntcp2-listener
command
Example: NTCP2Listener demonstration for I2P transport This example shows how to create and use an NTCP2Listener for accepting I2P NTCP2 transport connections with router identity management.
|
Example: NTCP2Listener demonstration for I2P transport This example shows how to create and use an NTCP2Listener for accepting I2P NTCP2 transport connections with router identity management. |
|
pool
command
Example: Connection pooling demonstration with complete handshakes
|
Example: Connection pooling demonstration with complete handshakes |
|
retry
command
Example: Handshake retry mechanisms with complete connections
|
Example: Handshake retry mechanisms with complete connections |
|
shutdown
command
Example: Graceful shutdown demonstration with complete handshakes
|
Example: Graceful shutdown demonstration with complete handshakes |
|
state
command
Example: Connection state management demonstration with complete handshakes
|
Example: Connection state management demonstration with complete handshakes |
|
transport
command
Example: Transport wrapping demonstration with complete handshakes
|
Example: Transport wrapping demonstration with complete handshakes |
|
Package handshake provides a generic modifier framework for transforming handshake data during Noise protocol exchanges.
|
Package handshake provides a generic modifier framework for transforming handshake data during Noise protocol exchanges. |
|
siphash
Package siphash implements the SipHash-2-4 length obfuscation modifier shared by NTCP2 and SSU2.
|
Package siphash implements the SipHash-2-4 length obfuscation modifier shared by NTCP2 and SSU2. |
|
internal
|
|
|
securemem
Package securemem provides helpers for safely erasing sensitive key material from memory.
|
Package securemem provides helpers for safely erasing sensitive key material from memory. |
|
Package mod provides shared helpers and secure utilities used across go-noise sub-packages, including state management and cryptographic zeroing.
|
Package mod provides shared helpers and secure utilities used across go-noise sub-packages, including state management and cryptographic zeroing. |
|
replaycache
Package replaycache provides a thread-safe, bounded, TTL-based cache for detecting replayed [32]byte keys.
|
Package replaycache provides a thread-safe, bounded, TTL-based cache for detecting replayed [32]byte keys. |
|
validation
Package validation provides shared validation helpers for go-noise sub-packages.
|
Package validation provides shared validation helpers for go-noise sub-packages. |
|
Package ntcp2 provides NTCP2-specific implementations for the Noise Protocol Framework supporting I2P's NTCP2 transport protocol with router identity and session management.
|
Package ntcp2 provides NTCP2-specific implementations for the Noise Protocol Framework supporting I2P's NTCP2 transport protocol with router identity and session management. |
|
Package ratchet provides ECIES-X25519-AEAD-Ratchet cryptographic primitives.
|
Package ratchet provides ECIES-X25519-AEAD-Ratchet cryptographic primitives. |
|
Package ssu2: config/addr re-exports from ssu2/config.
|
Package ssu2: config/addr re-exports from ssu2/config. |
|
config
Package ssu2 provides SSU2-specific implementations for the Noise Protocol Framework supporting I2P's SSU2 transport protocol with UDP-based connections and NAT traversal.
|
Package ssu2 provides SSU2-specific implementations for the Noise Protocol Framework supporting I2P's SSU2 transport protocol with UDP-based connections and NAT traversal. |
|
reliability
Package reliability provides SSU2 connection reliability components.
|
Package reliability provides SSU2 connection reliability components. |
|
server
Package server: type aliases for types from ssu2 sub-packages.
|
Package server: type aliases for types from ssu2 sub-packages. |
|
session
Package session: type aliases for types from ssu2 sub-packages.
|
Package session: type aliases for types from ssu2 sub-packages. |