use a rewriter instead
This commit is contained in:
parent
2e867583dc
commit
8a90646a68
3 changed files with 28 additions and 3 deletions
|
@ -23,7 +23,7 @@ func (r Resolver) Resolve(ctx context.Context, name string) (context.Context, ne
|
|||
return r.ResolveI2P(ctx, name)
|
||||
}
|
||||
|
||||
func (r Resolver) ResolveI2P(ctx context.Context, name string) (context.Context, *sam3.I2PDestHash, error) {
|
||||
func (r Resolver) ResolveI2P(ctx context.Context, name string) (context.Context, *sam3.I2PAddr, error) {
|
||||
if !r.ValidateI2PAddr(name) {
|
||||
return ctx, nil, fmt.Errorf("Error, not an allowed suffix")
|
||||
}
|
||||
|
@ -31,8 +31,7 @@ func (r Resolver) ResolveI2P(ctx context.Context, name string) (context.Context,
|
|||
if err != nil {
|
||||
return ctx, nil, err
|
||||
}
|
||||
v := raddr.DestHash()
|
||||
return ctx, &v, nil
|
||||
return ctx, &raddr, nil
|
||||
}
|
||||
|
||||
func (r Resolver) Cleanup() error {
|
||||
|
|
24
rewriter/rewriter.go
Normal file
24
rewriter/rewriter.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package rewriter
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
import (
|
||||
"github.com/eyedeekay/go-socks5"
|
||||
"github.com/eyedeekay/sam3"
|
||||
)
|
||||
|
||||
type Rewriter struct {
|
||||
network string
|
||||
}
|
||||
|
||||
func (r Rewriter) Rewrite(ctx context.Context, request *socks5.Request) (context.Context, *socks5.AddrSpec) {
|
||||
addr := request.DestAddr
|
||||
addr.FQDN = request.DestAddr.ADDR.(*sam3.I2PAddr).Base32()
|
||||
return ctx, addr
|
||||
}
|
||||
|
||||
func NewRewriter() Rewriter {
|
||||
var r Rewriter
|
||||
return &r
|
||||
}
|
|
@ -10,6 +10,7 @@ import (
|
|||
import (
|
||||
"github.com/eyedeekay/eeproxy/conn"
|
||||
"github.com/eyedeekay/eeproxy/resolve"
|
||||
"github.com/eyedeekay/eeproxy/rewriter"
|
||||
"github.com/eyedeekay/go-socks5"
|
||||
"github.com/eyedeekay/sam3"
|
||||
)
|
||||
|
@ -105,6 +106,7 @@ func NewManagerFromOptions(opts ...func(*Manager) error) (*Manager, error) {
|
|||
m.Config = socks5.Config{
|
||||
Resolver: r,
|
||||
Dial: m.Dial,
|
||||
Rewriter: NewRewriter(),
|
||||
}
|
||||
return &m, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue