Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auxiliary functionality for gotapdance register-on-behalf-of feature #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions pkg/registrars/registration/api-registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *APIRegistrar) registerBidirectional(cjSession *tapdance.ConjureSession,
for tries := 0; tries < r.maxRetries+1; tries++ {
logger := logger.WithField("attempt", strconv.Itoa(tries+1)+"/"+strconv.Itoa(r.maxRetries+1))

regResp, err := r.executeHTTPRequestBidirectional(ctx, payload, logger)
regResp, err := r.executeHTTPRequestBidirectional(ctx, payload, logger, cjSession)
if err != nil {
logger.Warnf("error in registration attempt: %v", err)
continue
Expand All @@ -150,8 +150,12 @@ func (r *APIRegistrar) registerBidirectional(cjSession *tapdance.ConjureSession,
logger.WithField("attempts", r.maxRetries+1).Warnf("all registration attempt(s) failed")

if r.secondaryRegistrar != nil {
logger.Debugf("trying secondary registration method")
return r.secondaryRegistrar.Register(cjSession, ctx)
if cjSession.RegisterOnBehalfOf {
logger.Debugf("Do not switch to secondary registration method if bdapi failed")
} else {
logger.Debugf("trying secondary registration method")
return r.secondaryRegistrar.Register(cjSession, ctx)
}
}

return nil, lib.ErrRegFailed
Expand Down Expand Up @@ -201,7 +205,7 @@ func (r APIRegistrar) executeHTTPRequest(ctx context.Context, payload []byte, lo
return nil
}

func (r APIRegistrar) executeHTTPRequestBidirectional(ctx context.Context, payload []byte, logger logrus.FieldLogger) (*pb.RegistrationResponse, error) {
func (r APIRegistrar) executeHTTPRequestBidirectional(ctx context.Context, payload []byte, logger logrus.FieldLogger, cjSession *tapdance.ConjureSession) (*pb.RegistrationResponse, error) {
// Create an instance of the ConjureReg struct to return; this will hold the updated phantom4 and phantom6 addresses received from registrar response
regResp := &pb.RegistrationResponse{}
// Make new HTTP request with given context, registrar, and paylaod
Expand All @@ -210,7 +214,11 @@ func (r APIRegistrar) executeHTTPRequestBidirectional(ctx context.Context, paylo
logger.Warnf("%v failed to create HTTP request to registration endpoint %s: %v", r.endpoint, err)
return regResp, err
}

if cjSession.RegisterOnBehalfOf {
clientIP := cjSession.RegisterFor.String()
clientIP2 := clientIP + ", " + clientIP
req.Header.Set("X-Forwarded-For", clientIP2)
}
resp, err := r.client.Do(req)
if err != nil {
logger.Warnf("%v failed to do HTTP request to registration endpoint %s: %v", r.endpoint, err)
Expand Down