Remove unused function, fix spelling, update godoc

This commit is contained in:
eyedeekay
2025-05-15 19:17:42 -04:00
parent 808f7d6fdf
commit 89c82cb2fe
10 changed files with 369 additions and 78 deletions

View File

@ -48,8 +48,8 @@ please keep up with these changes, as they will not be backward compatible and r
- [ ] Message parsing
- [ ] Message handling
- NetDB
- [/] Local storage
- [/] Persistence to disk
- [~] Local storage
- [~] Persistence to disk
- [X] Reseeding
- [ ] Lookups
- [ ] Expiry

View File

@ -79,7 +79,7 @@ close every transport that this transport muxer has
```go
func (tmux *TransportMuxer) Compatible(routerInfo router_info.RouterInfo) (compat bool)
```
is there a transport that we mux that is compatable with this router info?
is there a transport that we mux that is compatible with this router info?
#### func (*TransportMuxer) GetSession

View File

@ -23,11 +23,48 @@ type HandshakeState interface {
// CompleteHandshake completes the handshake
CompleteHandshake() error
SetEphemeralTransformer(transformer KeyTransformer)
GetHandshakeHash() []byte
SetPrologue(prologue []byte) error
MixHash(data []byte) error
MixKey(input []byte) ([]byte, error)
}
```
HandshakeState manages the Noise handshake state
#### type KeyTransformer
```go
type KeyTransformer interface {
ObfuscateKey(publicKey []byte) ([]byte, error)
DeobfuscateKey(obfuscatedKey []byte) ([]byte, error)
}
```
KeyTransformer defines operations for transforming keys during handshake
#### type NoOpTransformer
```go
type NoOpTransformer struct{}
```
NoOpTransformer is a default implementation that doesn't transform keys
#### func (*NoOpTransformer) DeobfuscateKey
```go
func (t *NoOpTransformer) DeobfuscateKey(obfuscatedKey []byte) ([]byte, error)
```
#### func (*NoOpTransformer) ObfuscateKey
```go
func (t *NoOpTransformer) ObfuscateKey(publicKey []byte) ([]byte, error)
```
handshake

View File

@ -74,7 +74,7 @@ func (tmux *TransportMuxer) Name() string {
func (tmux *TransportMuxer) GetSession(routerInfo router_info.RouterInfo) (s TransportSession, err error) {
log.WithField("router_info", routerInfo.String()).Debug("TransportMuxer: Attempting to get session")
for i, t := range tmux.trans {
// pick the first one that is compatable
// pick the first one that is compatible
if t.Compatible(routerInfo) {
log.WithField("transport_index", i).Debug("TransportMuxer: Found compatible transport, attempting to get session")
// try to get a session
@ -96,7 +96,7 @@ func (tmux *TransportMuxer) GetSession(routerInfo router_info.RouterInfo) (s Tra
return
}
// is there a transport that we mux that is compatable with this router info?
// is there a transport that we mux that is compatible with this router info?
func (tmux *TransportMuxer) Compatible(routerInfo router_info.RouterInfo) (compat bool) {
log.WithField("router_info", routerInfo.String()).Debug("TransportMuxer: Checking compatibility")
for i, t := range tmux.trans {

View File

@ -45,70 +45,17 @@ var (
func NewNoiseTransportSession(ri router_info.RouterInfo) (transport.TransportSession, error)
```
#### type NoiseHandshakeState
```go
type NoiseHandshakeState struct {
*noise.HandshakeState
}
```
#### func NewHandshakeState
```go
func NewHandshakeState(staticKey noise.DHKey, isInitiator bool) (*NoiseHandshakeState, error)
```
#### func (*NoiseHandshakeState) CompleteHandshake
```go
func (h *NoiseHandshakeState) CompleteHandshake() error
```
#### func (*NoiseHandshakeState) GenerateEphemeral
```go
func (h *NoiseHandshakeState) GenerateEphemeral() (*noise.DHKey, error)
```
GenerateEphemeral creates the ephemeral keypair that will be used in handshake
This needs to be separate so NTCP2 can obfuscate it
#### func (*NoiseHandshakeState) HandshakeComplete
```go
func (h *NoiseHandshakeState) HandshakeComplete() bool
```
#### func (*NoiseHandshakeState) ReadMessage
```go
func (h *NoiseHandshakeState) ReadMessage(message []byte) ([]byte, *noise.CipherState, *noise.CipherState, error)
```
#### func (*NoiseHandshakeState) SetEphemeral
```go
func (h *NoiseHandshakeState) SetEphemeral(key *noise.DHKey) error
```
SetEphemeral allows setting a potentially modified ephemeral key This is needed
for NTCP2's obfuscation layer
#### func (*NoiseHandshakeState) WriteMessage
```go
func (h *NoiseHandshakeState) WriteMessage(payload []byte) ([]byte, *noise.CipherState, *noise.CipherState, error)
```
#### type NoiseSession
```go
type NoiseSession struct {
router_info.RouterInfo
handshake.HandshakeState
*noise.CipherState
*sync.Cond
*NoiseTransport // The parent transport, which "Dialed" the connection to the peer with whom we established the session
handshake.HandshakeState
RecvQueue *cb.Queue
SendQueue *cb.Queue
VerifyCallback VerifyCallbackFunc
@ -275,13 +222,6 @@ func (noopt *NoiseTransport) Close() error
```
close the transport cleanly blocks until done returns an error if one happens
#### func (*NoiseTransport) Compatable
```go
func (noopt *NoiseTransport) Compatable(routerInfo router_info.RouterInfo) bool
```
Compatable return true if a routerInfo is compatable with this transport
#### func (*NoiseTransport) Compatible
```go

View File

@ -0,0 +1,179 @@
# handshake
--
import "github.com/go-i2p/go-i2p/lib/transport/noise/handshake"
![handshake.svg](handshake.svg)
## Usage
#### type HandshakeBuilder
```go
type HandshakeBuilder struct {
}
```
HandshakeBuilder constructs customized HandshakeState instances
#### func NewHandshakeBuilder
```go
func NewHandshakeBuilder() *HandshakeBuilder
```
NewHandshakeBuilder creates a new HandshakeBuilder with default values
#### func (*HandshakeBuilder) AsInitiator
```go
func (b *HandshakeBuilder) AsInitiator(isInitiator bool) *HandshakeBuilder
```
AsInitiator sets this handshake as the initiator
#### func (*HandshakeBuilder) Build
```go
func (b *HandshakeBuilder) Build() (handshake.HandshakeState, error)
```
Build creates a configured HandshakeState
#### func (*HandshakeBuilder) WithKeyTransformer
```go
func (b *HandshakeBuilder) WithKeyTransformer(transformer handshake.KeyTransformer) *HandshakeBuilder
```
WithKeyTransformer sets a custom key transformer
#### func (*HandshakeBuilder) WithPattern
```go
func (b *HandshakeBuilder) WithPattern(pattern noise.HandshakePattern) *HandshakeBuilder
```
WithPattern sets the handshake pattern
#### func (*HandshakeBuilder) WithPeerStaticKey
```go
func (b *HandshakeBuilder) WithPeerStaticKey(key []byte) *HandshakeBuilder
```
WithPeerStaticKey sets the peer's static key
#### func (*HandshakeBuilder) WithPrologue
```go
func (b *HandshakeBuilder) WithPrologue(prologue []byte) *HandshakeBuilder
```
WithPrologue sets the prologue data
#### func (*HandshakeBuilder) WithStaticKey
```go
func (b *HandshakeBuilder) WithStaticKey(key noise.DHKey) *HandshakeBuilder
```
WithStaticKey sets the local static key
#### type NoiseHandshakeState
```go
type NoiseHandshakeState struct {
noise.HandshakePattern
*noise.HandshakeState
handshake.KeyTransformer
*kdf.NoiseKDF
}
```
HandshakeState wraps noise.HandshakeState with additional functionality
#### func NewHandshakeState
```go
func NewHandshakeState(staticKey noise.DHKey, isInitiator bool) (*NoiseHandshakeState, error)
```
#### func (*NoiseHandshakeState) CompleteHandshake
```go
func (hs *NoiseHandshakeState) CompleteHandshake() error
```
CompleteHandshake implements handshake.HandshakeState
#### func (*NoiseHandshakeState) GenerateEphemeral
```go
func (hs *NoiseHandshakeState) GenerateEphemeral() (*noise.DHKey, error)
```
GenerateEphemeral implements handshake.HandshakeState
#### func (*NoiseHandshakeState) GetHandshakeHash
```go
func (hs *NoiseHandshakeState) GetHandshakeHash() []byte
```
GetHandshakeHash implements handshake.HandshakeState
#### func (*NoiseHandshakeState) HandshakeComplete
```go
func (hs *NoiseHandshakeState) HandshakeComplete() bool
```
HandshakeComplete implements handshake.HandshakeState
#### func (*NoiseHandshakeState) MixHash
```go
func (hs *NoiseHandshakeState) MixHash(data []byte) error
```
MixHash implements handshake.HandshakeState
#### func (*NoiseHandshakeState) MixKey
```go
func (hs *NoiseHandshakeState) MixKey(input []byte) ([]byte, error)
```
MixKey implements handshake.HandshakeState
#### func (*NoiseHandshakeState) ReadMessage
```go
func (hs *NoiseHandshakeState) ReadMessage(message []byte) ([]byte, *noise.CipherState, *noise.CipherState, error)
```
ReadMessage implements handshake.HandshakeState
#### func (*NoiseHandshakeState) SetEphemeral
```go
func (h *NoiseHandshakeState) SetEphemeral(key *noise.DHKey) error
```
SetEphemeral allows setting a potentially modified ephemeral key This is needed
for NTCP2's obfuscation layer
#### func (*NoiseHandshakeState) SetEphemeralTransformer
```go
func (hs *NoiseHandshakeState) SetEphemeralTransformer(transformer handshake.KeyTransformer)
```
SetEphemeralTransformer implements handshake.HandshakeState
#### func (*NoiseHandshakeState) SetPrologue
```go
func (hs *NoiseHandshakeState) SetPrologue(prologue []byte) error
```
SetPrologue implements handshake.HandshakeState
#### func (*NoiseHandshakeState) WriteMessage
```go
func (hs *NoiseHandshakeState) WriteMessage(payload []byte) ([]byte, *noise.CipherState, *noise.CipherState, error)
```
WriteMessage implements handshake.HandshakeState
handshake
github.com/go-i2p/go-i2p/lib/transport/noise/handshake
[go-i2p template file](/template.md)

View File

@ -0,0 +1,67 @@
# kdf
--
import "github.com/go-i2p/go-i2p/lib/transport/noise/kdf"
![kdf.svg](kdf.svg)
## Usage
#### type NoiseKDF
```go
type NoiseKDF struct {
}
```
NoiseKDF handles key derivation functions for Noise protocols
#### func NewNoiseKDF
```go
func NewNoiseKDF(protocolName []byte) *NoiseKDF
```
NewNoiseKDF creates a new KDF instance with the protocol name
#### func (*NoiseKDF) DeriveSessionKeys
```go
func (k *NoiseKDF) DeriveSessionKeys() (sendKey, recvKey []byte, err error)
```
DeriveSessionKeys derives transport keys from the KDF state
#### func (*NoiseKDF) GetHandshakeHash
```go
func (k *NoiseKDF) GetHandshakeHash() []byte
```
GetHandshakeHash returns the current handshake hash
#### func (*NoiseKDF) MixHash
```go
func (k *NoiseKDF) MixHash(data []byte) error
```
MixHash updates the handshake hash with new data
#### func (*NoiseKDF) MixKey
```go
func (k *NoiseKDF) MixKey(input []byte) ([]byte, error)
```
MixKey derives a new key from the chaining key and input material
#### func (*NoiseKDF) SetHash
```go
func (k *NoiseKDF) SetHash(hash []byte)
```
kdf
github.com/go-i2p/go-i2p/lib/transport/noise/kdf
[go-i2p template file](/template.md)

View File

@ -156,16 +156,6 @@ func (c *NoiseTransport) getSession(routerInfo router_info.RouterInfo) (transpor
return session, nil
}
// Compatable return true if a routerInfo is compatable with this transport
func (noopt *NoiseTransport) Compatable(routerInfo router_info.RouterInfo) bool {
_, ok := noopt.peerConnections[routerInfo.IdentHash()]
log.WithFields(logrus.Fields{
"router_info": routerInfo.String(),
"compatible": ok,
}).Debug("NoiseTransport: Checking compatibility")
return ok
}
// close the transport cleanly
// blocks until done
// returns an error if one happens

View File

@ -134,6 +134,13 @@ func NewNTCP2Session(routerInfo router_info.RouterInfo) (*NTCP2Session, error)
NewNTCP2Session creates a new NTCP2 session using the existing noise
implementation
#### func (*NTCP2Session) AddDelayForSecurity
```go
func (c *NTCP2Session) AddDelayForSecurity()
```
addDelayForSecurity adds a small random delay to resist probing
#### func (*NTCP2Session) CreateHandshakeProcessors
```go
@ -279,6 +286,35 @@ SessionRequest (Message 1) 2. Receives and processes SessionCreated (Message 2)
3. Creates and sends SessionConfirmed (Message 3) After successful completion,
the session is established and ready for data exchange.
#### func (*NTCP2Session) ProcessEphemeralKey
```go
func (c *NTCP2Session) ProcessEphemeralKey(obfuscatedX []byte, hs *handshake.HandshakeState) ([]byte, error)
```
processEphemeralKey deobfuscates and validates the ephemeral key
#### func (*NTCP2Session) ReadAndValidatePadding
```go
func (c *NTCP2Session) ReadAndValidatePadding(conn net.Conn, paddingLen int) error
```
readAndValidatePadding reads the padding from the connection
#### func (*NTCP2Session) ReadEphemeralKey
```go
func (c *NTCP2Session) ReadEphemeralKey(conn net.Conn) ([]byte, error)
```
readEphemeralKey reads the ephemeral key (X) from the connection
#### func (*NTCP2Session) ValidateTimestamp
```go
func (s *NTCP2Session) ValidateTimestamp(timestamp time.Time) error
```
Add this method to NTCP2Session ValidateTimestamp validates a timestamp is
within acceptable range
#### type NTCP2Transport
```go
@ -321,6 +357,13 @@ func (t *NTCP2Transport) Compatible(routerInfo router_info.RouterInfo) bool
func (t *NTCP2Transport) GetSession(routerInfo router_info.RouterInfo) (transport.TransportSession, error)
```
#### func (*NTCP2Transport) LocalStaticKey
```go
func (s *NTCP2Transport) LocalStaticKey() ([32]byte, error)
```
LocalStaticKey is equal to the NTCP2 static public key, found in our router info
#### func (*NTCP2Transport) Name
```go

View File

@ -83,6 +83,13 @@ func (h *HandshakeState) GenerateEphemeral() (*noise.DHKey, error)
```
GenerateEphemeral implements handshake.HandshakeState.
#### func (*HandshakeState) GetHandshakeHash
```go
func (h *HandshakeState) GetHandshakeHash() []byte
```
GetHandshakeHash implements handshake.HandshakeState.
#### func (*HandshakeState) HandshakeComplete
```go
@ -90,6 +97,34 @@ func (h *HandshakeState) HandshakeComplete() bool
```
HandshakeComplete implements handshake.HandshakeState.
#### func (*HandshakeState) MixHash
```go
func (h *HandshakeState) MixHash(data []byte) error
```
MixHash implements handshake.HandshakeState.
#### func (*HandshakeState) MixKey
```go
func (h *HandshakeState) MixKey(input []byte) ([]byte, error)
```
MixKey implements handshake.HandshakeState.
#### func (*HandshakeState) SetEphemeralTransformer
```go
func (h *HandshakeState) SetEphemeralTransformer(transformer handshake.KeyTransformer)
```
SetEphemeralTransformer implements handshake.HandshakeState.
#### func (*HandshakeState) SetPrologue
```go
func (h *HandshakeState) SetPrologue(prologue []byte) error
```
SetPrologue implements handshake.HandshakeState.
#### func (*HandshakeState) WriteMessage
```go