Add new, address generation functions

This commit is contained in:
eyedeekay
2025-02-26 19:31:57 -05:00
parent ae4970b3a9
commit 7f78fdf784
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package ntcp
import (
"time"
"github.com/go-i2p/go-i2p/lib/common/router_address"
"github.com/samber/oops"
)
func (t *NTCP2Transport) Address() (*router_address.RouterAddress, error) {
// Construct a complete NTCP2 address for the transport:
timeStamp := t.GetCurrentTime().Add(10 * time.Minute)
// 2. Initialize an empty options map.
options := make(map[string]string)
// 3. Create a new RouterAddress with the provided parameters.
addr, err := router_address.NewRouterAddress(8, timeStamp, t.Name(), options)
if err != nil {
return nil, oops.Errorf("failed to create RouterAddress: %w", err)
}
// 4. Return the created address or an error if the creation fails.
return addr, nil
}

20
lib/transport/ntcp/new.go Normal file
View File

@ -0,0 +1,20 @@
package ntcp
import (
"github.com/go-i2p/go-i2p/lib/common/router_info"
"github.com/go-i2p/go-i2p/lib/transport/noise"
"github.com/go-i2p/go-i2p/lib/util/time/sntp"
)
func NewNTCP2Transport(routerInfo *router_info.RouterInfo) (*NTCP2Transport, error) {
defaultClient := &sntp.DefaultNTPClient{}
timestamper := sntp.NewRouterTimestamper(defaultClient)
n := &NTCP2Transport{
NoiseTransport: &noise.NoiseTransport{
RouterInfo: *routerInfo,
},
RouterTimestamper: timestamper,
transportStyle: NTCP_PROTOCOL_NAME,
}
return n, nil
}