-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sessionresolver): minor changes in files and types naming (#810
) Part of ooni/probe#2135
- Loading branch information
1 parent
beba543
commit a02cc61
Showing
14 changed files
with
145 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Package sessionresolver contains the resolver used by the session. This | ||
// resolver will try to figure out which is the best service for running | ||
// domain name resolutions and will consistently use it. | ||
// | ||
// Occasionally this code will also swap the best resolver with other | ||
// ~good resolvers to give them a chance to perform. | ||
// | ||
// The penalty/reward mechanism is strongly derivative, so the code should | ||
// adapt ~quickly to changing network conditions. Occasionally, we will | ||
// have longer resolutions when trying out other resolvers. | ||
// | ||
// At the beginning we randomize the known resolvers so that we do not | ||
// have any preferential ordering. The initial resolutions may be slower | ||
// if there are many issues with resolvers. | ||
// | ||
// The system resolver is given the lowest priority at the beginning | ||
// but it will of course be the most popular resolver if anything else | ||
// is failing us. (We will still occasionally probe for other working | ||
// resolvers and increase their score on success.) | ||
// | ||
// We also support a socks5 proxy. When such a proxy is configured, | ||
// the code WILL skip http3 resolvers AS WELL AS the system | ||
// resolver, in an attempt to avoid leaking your queries. | ||
package sessionresolver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
package sessionresolver | ||
|
||
// | ||
// Error wrapping | ||
// | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// errwrapper wraps an error to include the URL of the | ||
// errWrapper wraps an error to include the URL of the | ||
// resolver that we're currently using. | ||
type errwrapper struct { | ||
error | ||
URL string | ||
type errWrapper struct { | ||
err error | ||
url string | ||
} | ||
|
||
// newErrWrapper creates a new err wrapper. | ||
func newErrWrapper(err error, URL string) *errWrapper { | ||
return &errWrapper{ | ||
err: err, | ||
url: URL, | ||
} | ||
} | ||
|
||
// Error implements error.Error. | ||
func (ew *errwrapper) Error() string { | ||
return fmt.Sprintf("<%s> %s", ew.URL, ew.error.Error()) | ||
func (ew *errWrapper) Error() string { | ||
return fmt.Sprintf("<%s> %s", ew.url, ew.err.Error()) | ||
} | ||
|
||
// Is allows consumers to query for the type of the underlying error. | ||
func (ew *errwrapper) Is(target error) bool { | ||
return errors.Is(ew.error, target) | ||
func (ew *errWrapper) Is(target error) bool { | ||
return errors.Is(ew.err, target) | ||
} | ||
|
||
// Unwrap returns the underlying error. | ||
func (ew *errWrapper) Unwrap() error { | ||
return ew.err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sessionresolver | ||
|
||
// | ||
// JSON codec | ||
// | ||
|
||
import "encoding/json" | ||
|
||
// jsonCodec encodes to/decodes from JSON. | ||
type jsonCodec interface { | ||
// Encode encodes v as a JSON stream of bytes. | ||
Encode(v interface{}) ([]byte, error) | ||
|
||
// Decode decodes b from a JSON stream of bytes. | ||
Decode(b []byte, v interface{}) error | ||
} | ||
|
||
// codec always returns a valid jsonCodec. | ||
func (r *Resolver) codec() jsonCodec { | ||
if r.jsonCodec != nil { | ||
return r.jsonCodec | ||
} | ||
return &jsonCodecStdlib{} | ||
} | ||
|
||
// jsonCodecStdlib is the default codec. | ||
type jsonCodecStdlib struct{} | ||
|
||
// Decode implements jsonCodec.Decode. | ||
func (*jsonCodecStdlib) Decode(b []byte, v interface{}) error { | ||
return json.Unmarshal(b, v) | ||
} | ||
|
||
// Encode implements jsonCodec.Encode. | ||
func (*jsonCodecStdlib) Encode(v interface{}) ([]byte, error) { | ||
return json.Marshal(v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...internal/sessionresolver/childresolver.go → ...engine/internal/sessionresolver/lookup.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package sessionresolver | ||
|
||
// | ||
// Actual lookup code | ||
// | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package sessionresolver | ||
|
||
// | ||
// Code for creating a new child resolver | ||
// | ||
|
||
import ( | ||
"math/rand" | ||
"strings" | ||
|
Oops, something went wrong.