mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-13 11:54:46 -04:00
Add new, address generation functions
This commit is contained in:
23
lib/transport/ntcp/address.go
Normal file
23
lib/transport/ntcp/address.go
Normal 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
20
lib/transport/ntcp/new.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user