Skip to content

Commit

Permalink
Add tworeqresp to requester and responder
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyech committed Jun 24, 2024
1 parent 04b93bc commit e856d1f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
16 changes: 16 additions & 0 deletions pkg/registrars/dns-registrar/tworeqresp/requester.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package tworeqresp

import (
"context"
"crypto/rand"
"fmt"
"net"

pb "github.com/refraction-networking/conjure/proto"
"google.golang.org/protobuf/proto"
)

type dialFunc = func(ctx context.Context, network, addr string) (net.Conn, error)

const idLen = 8

type onerequester interface {
RequestAndRecv(sendBytes []byte) ([]byte, error)
Close() error
SetDialer(dialer dialFunc) error
}

type Requester struct {
Expand Down Expand Up @@ -76,3 +82,13 @@ func splitIntoChunks(data []byte, mtu int) [][]byte {

return chunks
}

// Close closes the parent transport
func (r *Requester) Close() error {
return r.parent.Close()
}

// SetDialer sets the parent dialer
func (r *Requester) SetDialer(dialer dialFunc) error {
return r.parent.SetDialer(dialer)
}
6 changes: 6 additions & 0 deletions pkg/registrars/dns-registrar/tworeqresp/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type oneresponder interface {
RecvAndRespond(getResponse func([]byte) ([]byte, error)) error
Close() error
}

type Responder struct {
Expand Down Expand Up @@ -91,3 +92,8 @@ func (r *Responder) RecvAndRespond(parentGetResponse func([]byte) ([]byte, error
}
return r.parent.RecvAndRespond(getResponse)
}

// Close closes the parent transport
func (r *Responder) Close() error {
return r.parent.Close()
}
7 changes: 5 additions & 2 deletions pkg/registrars/registration/dns-registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/pion/stun"
"github.com/refraction-networking/conjure/pkg/registrars/dns-registrar/requester"
"github.com/refraction-networking/conjure/pkg/registrars/dns-registrar/tworeqresp"
"github.com/refraction-networking/conjure/pkg/registrars/lib"
pb "github.com/refraction-networking/conjure/proto"
"github.com/refraction-networking/gotapdance/tapdance"
Expand All @@ -18,7 +19,7 @@ import (
)

type DNSRegistrar struct {
req *requester.Requester
req *tworeqresp.Requester
maxRetries int
connectionDelay time.Duration
bidirectional bool
Expand Down Expand Up @@ -63,13 +64,15 @@ func NewDNSRegistrar(config *Config) (*DNSRegistrar, error) {
return nil, fmt.Errorf("error creating requester: %v", err)
}

tworeq, err := tworeqresp.NewRequester(req, 80)

ip, err := getPublicIp(config.STUNAddr)
if err != nil {
return nil, fmt.Errorf("failed to get public IP: %v", err)
}

return &DNSRegistrar{
req: req,
req: tworeq,
ip: ip,
maxRetries: config.MaxRetries,
bidirectional: config.Bidirectional,
Expand Down
7 changes: 5 additions & 2 deletions pkg/regserver/dnsregserver/dnsregserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/refraction-networking/conjure/pkg/metrics"
"github.com/refraction-networking/conjure/pkg/registrars/dns-registrar/responder"
"github.com/refraction-networking/conjure/pkg/registrars/dns-registrar/tworeqresp"
"github.com/refraction-networking/conjure/pkg/regserver/regprocessor"
pb "github.com/refraction-networking/conjure/proto"
log "github.com/sirupsen/logrus"
Expand All @@ -22,7 +23,7 @@ type registrar interface {
// DNSRegServer provides an interface to forward DNS registration requests. Use a dns responder to receive requests and send responses.
type DNSRegServer struct {
// dns responder to recieve and forward responses with
dnsResponder *responder.Responder
dnsResponder *tworeqresp.Responder
processor registrar
latestCCGen uint32
logger log.FieldLogger
Expand All @@ -45,8 +46,10 @@ func NewDNSRegServer(domain string, udpAddr string, privkey []byte, regprocessor
return nil, fmt.Errorf("failed to create DNS responder: %v", err)
}

tworesponder, err := tworeqresp.NewResponder(respder)

return &DNSRegServer{
dnsResponder: respder,
dnsResponder: tworesponder,
processor: regprocessor,
latestCCGen: latestClientConfGeneration,
logger: logger,
Expand Down

0 comments on commit e856d1f

Please sign in to comment.