Skip to content

Commit

Permalink
Use new eventual
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Nov 19, 2024
1 parent 680ac88 commit 9dc10f7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
22 changes: 15 additions & 7 deletions context.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package fronted

import (
"context"
"crypto/x509"
"fmt"
"net/http"
"time"

tls "github.com/refraction-networking/utls"

"github.com/getlantern/eventual"
"github.com/getlantern/eventual/v2"
)

var defaultContext = newFrontingContext("default")
Expand Down Expand Up @@ -64,8 +65,9 @@ func (fctx *frontingContext) ConfigureWithHello(pool *x509.CertPool, providers m
return fmt.Errorf("no fronted providers for %s context", fctx.name)
}

_existing, ok := fctx.instance.Get(0)
if ok && _existing != nil {
if _existing, err := fctx.instance.Get(eventual.DontWait); err != nil {
log.Errorf("Error getting existing instance for %s context: %s", fctx.name, err)
} else if _existing != nil {
existing := _existing.(*fronted)
log.Debugf("Closing cache from existing instance for %s context", fctx.name)
existing.closeCache()
Expand All @@ -86,8 +88,10 @@ func (fctx *frontingContext) ConfigureWithHello(pool *x509.CertPool, providers m
// returns nil, false.
func (fctx *frontingContext) NewFronted(timeout time.Duration) (http.RoundTripper, bool) {
start := time.Now()
instance, ok := fctx.instance.Get(timeout)
if !ok {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
instance, err := fctx.instance.Get(ctx)
if err != nil {
log.Errorf("No DirectHttpClient available within %v for context %s", timeout, fctx.name)
return nil, false
} else {
Expand All @@ -98,8 +102,12 @@ func (fctx *frontingContext) NewFronted(timeout time.Duration) (http.RoundTrippe

// Close closes any existing cache file in the default contexxt.
func (fctx *frontingContext) Close() {
_existing, ok := fctx.instance.Get(0)
if ok && _existing != nil {
_existing, err := fctx.instance.Get(eventual.DontWait)
if err != nil {
log.Errorf("Error getting existing instance for %s context: %s", fctx.name, err)
return
}
if _existing != nil {
existing := _existing.(*fronted)
log.Debugf("Closing cache from existing instance in %s context", fctx.name)
existing.closeCache()
Expand Down
5 changes: 3 additions & 2 deletions fronted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"
"time"

"github.com/getlantern/eventual/v2"
. "github.com/getlantern/waitforserver"
tls "github.com/refraction-networking/utls"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -103,8 +104,8 @@ func doTestDomainFronting(t *testing.T, cacheFile string, expectedMasqueradesAtE
}
require.True(t, doCheck(client, http.MethodGet, http.StatusOK, getURL))

instance, ok := testContext.instance.Get(0)
require.True(t, ok)
instance, err := testContext.instance.Get(eventual.DontWait)
require.NoError(t, err)
d := instance.(*fronted)

// Check the number of masquerades at the end, waiting until we get the right number
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/getlantern/fronted
go 1.22.3

require (
github.com/getlantern/eventual v1.0.0
github.com/getlantern/eventual/v2 v2.0.2
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7
github.com/getlantern/idletiming v0.0.0-20201229174729-33d04d220c4e
github.com/getlantern/keyman v0.0.0-20180207174507-f55e7280e93a
github.com/getlantern/netx v0.0.0-20210806160745-b824e2cad607
github.com/getlantern/ops v0.0.0-20230424193308-26325dfed3cf
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,24 @@ github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7/go.mod h1:l+xpFB
github.com/getlantern/errors v1.0.1/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A=
github.com/getlantern/errors v1.0.3 h1:Ne4Ycj7NI1BtSyAfVeAT/DNoxz7/S2BUc3L2Ht1YSHE=
github.com/getlantern/errors v1.0.3/go.mod h1:m8C7H1qmouvsGpwQqk/6NUpIVMpfzUPn608aBZDYV04=
github.com/getlantern/eventual v1.0.0 h1:q56jlZhiDeWvdrc0QJ12AaWqcu/Z67wDDjdAUKGnYqc=
github.com/getlantern/eventual v1.0.0/go.mod h1:xL9T/pQI7i44INFSsKf4zDNz5bXA7P18j1cNd5qy/yI=
github.com/getlantern/eventual/v2 v2.0.2 h1:7b3N2oQBVqSHwm/8u7C8b6W+OkkjgZSmwUc1AdIkrHc=
github.com/getlantern/eventual/v2 v2.0.2/go.mod h1:o1VZHRk8UArBra+pwPSi23WrahBG4qgg4/ew6Mmlq84=
github.com/getlantern/fdcount v0.0.0-20190912142506-f89afd7367c4 h1:JdD4XSaT6/j6InM7MT1E4WRvzR8gurxfq53A3ML3B/Q=
github.com/getlantern/fdcount v0.0.0-20190912142506-f89afd7367c4/go.mod h1:XZwE+iIlAgr64OFbXKFNCllBwV4wEipPx8Hlo2gZdbM=
github.com/getlantern/filepersist v0.0.0-20160317154340-c5f0cd24e799 h1:FhkPUYCQYmoxS02r2GRrIV7dahUIncRl36xzs3/mnjA=
github.com/getlantern/filepersist v0.0.0-20160317154340-c5f0cd24e799/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 h1:guBYzEaLz0Vfc/jv0czrr2z7qyzTOGC9hiQ0VC+hKjk=
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7/go.mod h1:zx/1xUUeYPy3Pcmet8OSXLbF47l+3y6hIPpyLWoR9oc=
github.com/getlantern/grtrack v0.0.0-20160824195228-cbf67d3fa0fd h1:GPrx88jy222gMuRHXxBSViT/3zdNO210nRAaXn+lL6s=
github.com/getlantern/grtrack v0.0.0-20160824195228-cbf67d3fa0fd/go.mod h1:RkQEgBdrJCH5tYJP2D+a/aJ216V3c9q8w/tCJtEiDoY=
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0=
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o=
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc=
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA=
github.com/getlantern/idletiming v0.0.0-20201229174729-33d04d220c4e h1:b0VWlP1TB369RANq5GnV76sGDm98eQwVJaaoH8OXOmw=
github.com/getlantern/idletiming v0.0.0-20201229174729-33d04d220c4e/go.mod h1:McaLC6faRlxJ9QjjqSjpEeYIjKnKA8+dzjoR+eYXCio=
github.com/getlantern/keyman v0.0.0-20180207174507-f55e7280e93a h1:SBw2c296eaLrrnydtLhcjgvNB1mDaXF1SSfW4DGt0kk=
github.com/getlantern/keyman v0.0.0-20180207174507-f55e7280e93a/go.mod h1:FMf0g72BHs14jVcD8i8ubEk4sMB6JdidBn67d44i3ws=
github.com/getlantern/mockconn v0.0.0-20190708122800-637bd46d8034/go.mod h1:+F5GJ7qGpQ03DBtcOEyQpM30ix4BLswdaojecFtsdy8=
github.com/getlantern/mockconn v0.0.0-20191023022503-481dbcceeb58/go.mod h1:+F5GJ7qGpQ03DBtcOEyQpM30ix4BLswdaojecFtsdy8=
github.com/getlantern/mockconn v0.0.0-20200818071412-cb30d065a848 h1:2MhMMVBTnaHrst6HyWFDhwQCaJ05PZuOv1bE2gN8WFY=
github.com/getlantern/mockconn v0.0.0-20200818071412-cb30d065a848/go.mod h1:+F5GJ7qGpQ03DBtcOEyQpM30ix4BLswdaojecFtsdy8=
github.com/getlantern/mtime v0.0.0-20170117193331-ba114e4a82b0/go.mod h1:u537FS7ld4Whf7h7/0ql/myAudWWBNgeRhgE9XXH4Pk=
github.com/getlantern/mtime v0.0.0-20200228202836-084e1d8282b0/go.mod h1:GfzwugvtH7YcmNIrHHizeyImsgEdyL88YkdnK28B14c=
github.com/getlantern/mtime v0.0.0-20200417132445-23682092d1f7 h1:03J6Cb42EG06lHgpOFGm5BOax4qFqlSbSeKO2RGrj2g=
github.com/getlantern/mtime v0.0.0-20200417132445-23682092d1f7/go.mod h1:GfzwugvtH7YcmNIrHHizeyImsgEdyL88YkdnK28B14c=
github.com/getlantern/netx v0.0.0-20190110220209-9912de6f94fd/go.mod h1:wKdY0ikOgzrWSeB9UyBVKPRhjXQ+vTb+BPeJuypUuNE=
Expand Down

0 comments on commit 9dc10f7

Please sign in to comment.