Stub the remaining instantiators

This commit is contained in:
eyedeekay
2025-02-03 21:21:27 -05:00
parent a58bdf4858
commit 141fd98442
2 changed files with 72 additions and 0 deletions

29
lib/http/client/new.go Normal file
View File

@ -0,0 +1,29 @@
package httpclient
import (
"strings"
i2pconv "github.com/go-i2p/go-i2ptunnel-config/lib"
i2ptunnel "github.com/go-i2p/go-i2ptunnel/lib/core"
"github.com/go-i2p/onramp"
)
// NewHTTPClient creates a new HTTP Client tunnel with the given configuration
func NewHTTPClient(config i2pconv.TunnelConfig, samAddr string) (*HTTPClient, error) {
keys, options, err := config.SAMTunnel()
if err != nil {
return nil, err
}
name := strings.ReplaceAll(config.Name, " ", "_")
garlic, err := onramp.NewGarlic(name, samAddr, options)
if err != nil {
return nil, err
}
garlic.ServiceKeys = keys
return &HTTPClient{
TunnelConfig: config,
Garlic: garlic,
I2PTunnelStatus: i2ptunnel.I2PTunnelStatusStopped,
done: make(chan struct{}),
}, nil
}

43
lib/http/server/new.go Normal file
View File

@ -0,0 +1,43 @@
package httpserver
import (
"net"
"strconv"
"strings"
i2pconv "github.com/go-i2p/go-i2ptunnel-config/lib"
i2ptunnel "github.com/go-i2p/go-i2ptunnel/lib/core"
limitedlistener "github.com/go-i2p/go-limit"
"github.com/go-i2p/onramp"
)
// NewHTTPServer creates a new HTTP Server tunnel with the given configuration
func NewHTTPServer(config i2pconv.TunnelConfig, samAddr string) (*HTTPServer, error) {
keys, options, err := config.SAMTunnel()
if err != nil {
return nil, err
}
name := strings.ReplaceAll(config.Name, " ", "_")
garlic, err := onramp.NewGarlic(name, samAddr, options)
if err != nil {
return nil, err
}
garlic.ServiceKeys = keys
localPort := strconv.Itoa(config.Port)
localAddr := net.JoinHostPort(config.Interface, localPort)
addr, err := net.ResolveTCPAddr("tcp", localAddr)
if err != nil {
return nil, err
}
return &HTTPServer{
TunnelConfig: config,
Garlic: garlic,
Addr: addr,
I2PTunnelStatus: i2ptunnel.I2PTunnelStatusStopped,
LimitedConfig: limitedlistener.LimitedConfig{
MaxConns: 1000,
RateLimit: 100,
},
done: make(chan struct{}),
}, nil
}