mirror of
https://github.com/go-i2p/go-i2ptunnel.git
synced 2025-06-16 20:13:36 -04:00
Stub the remaining instantiators
This commit is contained in:
29
lib/http/client/new.go
Normal file
29
lib/http/client/new.go
Normal 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
43
lib/http/server/new.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user