Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
id
auth
Commits
fdccd853
Commit
fdccd853
authored
Jan 29, 2019
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update go-common
parent
47ae82f7
Pipeline
#2157
passed with stages
in 1 minute and 28 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
24 deletions
+73
-24
vendor/git.autistici.org/ai3/go-common/README.md
vendor/git.autistici.org/ai3/go-common/README.md
+22
-0
vendor/git.autistici.org/ai3/go-common/clientutil/balancer.go
...or/git.autistici.org/ai3/go-common/clientutil/balancer.go
+37
-10
vendor/vendor.json
vendor/vendor.json
+14
-14
No files found.
vendor/git.autistici.org/ai3/go-common/README.md
0 → 100644
View file @
fdccd853
ai3/go-common
===
Common code for ai3 services and tools.
A quick overview of the contents:
*
[
client
](
clientutil/
)
and
[
server
](
serverutil/
)
HTTP-based
"RPC" implementation, just JSON POST requests but with retries,
backoff, timeouts, tracing, etc.
*
[
server implementation of a line-based protocol over a UNIX socket
](
unix/
)
*
a
[
LDAP connection pool
](
ldap/
)
*
a
[
password hashing library
](
pwhash/
)
that uses fancy advanced
crypto by default but is also backwards compatible with old
libc crypto.
*
utilities to
[
manage encryption keys
](
userenckey/
)
, themselves
encrypted with a password and a KDF.
vendor/git.autistici.org/ai3/go-common/clientutil/balancer.go
View file @
fdccd853
...
...
@@ -98,28 +98,35 @@ func newBalancedBackend(config *BackendConfig, resolver resolver) (*balancedBack
// with a JSON-encoded request body. It will attempt to decode the
// response body as JSON.
func
(
b
*
balancedBackend
)
Call
(
ctx
context
.
Context
,
shard
,
path
string
,
req
,
resp
interface
{})
error
{
// Serialize the request body.
data
,
err
:=
json
.
Marshal
(
req
)
if
err
!=
nil
{
return
err
}
var
tg
targetGenerator
=
b
.
backendTracker
if
b
.
sharded
{
if
shard
==
""
{
return
fmt
.
Errorf
(
"call without shard to sharded service %s"
,
b
.
baseURI
.
String
())
}
tg
=
newShardedGenerator
(
shard
,
b
.
baseURI
.
Host
,
b
.
resolver
)
// Create the target sequence for this call. If there are multiple
// targets, reduce the timeout on each individual call accordingly to
// accomodate eventual failover.
seq
,
err
:=
b
.
makeSequence
(
shard
)
if
err
!=
nil
{
return
err
}
innerTimeout
:=
1
*
time
.
Hour
if
deadline
,
ok
:=
ctx
.
Deadline
();
ok
{
innerTimeout
=
time
.
Until
(
deadline
)
/
time
.
Duration
(
seq
.
Len
())
}
seq
:=
newSequence
(
tg
)
b
.
log
.
Printf
(
"%016x: initialized"
,
seq
.
ID
())
// Call the backends in the sequence until one succeeds, with an
// exponential backoff policy controlled by the outer Context.
var
httpResp
*
http
.
Response
err
=
backoff
.
Retry
(
func
()
error
{
req
,
rerr
:=
b
.
newJSONRequest
(
path
,
shard
,
data
)
if
rerr
!=
nil
{
return
rerr
}
httpResp
,
rerr
=
b
.
do
(
ctx
,
seq
,
req
)
innerCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
innerTimeout
)
httpResp
,
rerr
=
b
.
do
(
innerCtx
,
seq
,
req
)
cancel
()
return
rerr
},
backoff
.
WithContext
(
newExponentialBackOff
(),
ctx
))
if
err
!=
nil
{
...
...
@@ -127,16 +134,34 @@ func (b *balancedBackend) Call(ctx context.Context, shard, path string, req, res
}
defer
httpResp
.
Body
.
Close
()
// nolint
// Decode the response.
if
httpResp
.
Header
.
Get
(
"Content-Type"
)
!=
"application/json"
{
return
errors
.
New
(
"not a JSON response"
)
}
if
resp
==
nil
{
return
nil
}
return
json
.
NewDecoder
(
httpResp
.
Body
)
.
Decode
(
resp
)
}
// Initialize a new target sequence.
func
(
b
*
balancedBackend
)
makeSequence
(
shard
string
)
(
*
sequence
,
error
)
{
var
tg
targetGenerator
=
b
.
backendTracker
if
b
.
sharded
{
if
shard
==
""
{
return
nil
,
fmt
.
Errorf
(
"call without shard to sharded service %s"
,
b
.
baseURI
.
String
())
}
tg
=
newShardedGenerator
(
shard
,
b
.
baseURI
.
Host
,
b
.
resolver
)
}
seq
:=
newSequence
(
tg
)
if
seq
.
Len
()
==
0
{
return
nil
,
errNoTargets
}
b
.
log
.
Printf
(
"%016x: initialized"
,
seq
.
ID
())
return
seq
,
nil
}
// Return the URI to be used for the request. This is used both in the
// Host HTTP header and as the TLS server name used to pick a server
// certificate (if using TLS).
...
...
@@ -213,6 +238,8 @@ func newSequence(tg targetGenerator) *sequence {
func
(
s
*
sequence
)
ID
()
uint64
{
return
s
.
id
}
func
(
s
*
sequence
)
Len
()
int
{
return
len
(
s
.
targets
)
}
func
(
s
*
sequence
)
reloadTargets
()
{
targets
:=
s
.
tg
.
getTargets
()
if
len
(
targets
)
>
0
{
...
...
vendor/vendor.json
View file @
fdccd853
...
...
@@ -3,40 +3,40 @@
"ignore"
:
"test"
,
"package"
:
[
{
"checksumSHA1"
:
"
pLvPnUablirQucyALgrso9hLG4E
="
,
"checksumSHA1"
:
"
mqNsLVty/oAcBDXv2DZeqMtGeaY
="
,
"path"
:
"git.autistici.org/ai3/go-common"
,
"revision"
:
"
be955ddc61cf2c555747032befd4ff1a7d0b8097
"
,
"revisionTime"
:
"201
8-11-23T00:00:52
Z"
"revision"
:
"
0868f2647fefb9c3855bb6242aae8aab6d0ddc6d
"
,
"revisionTime"
:
"201
9-01-29T12:17:45
Z"
},
{
"checksumSHA1"
:
"
1ChQcW9Biu/AgiKjsbJFg/+WhjQ
="
,
"checksumSHA1"
:
"
hKJhn/0mTkaYIHwFTy+W9TLr09M
="
,
"path"
:
"git.autistici.org/ai3/go-common/clientutil"
,
"revision"
:
"
be955ddc61cf2c555747032befd4ff1a7d0b8097
"
,
"revisionTime"
:
"201
8-11-23T00:00:52
Z"
"revision"
:
"
0868f2647fefb9c3855bb6242aae8aab6d0ddc6d
"
,
"revisionTime"
:
"201
9-01-29T12:17:45
Z"
},
{
"checksumSHA1"
:
"npDdYYmInhdVxcCpOQ844cVlfzQ="
,
"path"
:
"git.autistici.org/ai3/go-common/ldap"
,
"revision"
:
"
be955ddc61cf2c555747032befd4ff1a7d0b8097
"
,
"revisionTime"
:
"201
8-11-23T00:00:52
Z"
"revision"
:
"
0868f2647fefb9c3855bb6242aae8aab6d0ddc6d
"
,
"revisionTime"
:
"201
9-01-29T12:17:45
Z"
},
{
"checksumSHA1"
:
"mfFIqmwojDqQdJvjLI3y7YCQ+2c="
,
"path"
:
"git.autistici.org/ai3/go-common/pwhash"
,
"revision"
:
"
be955ddc61cf2c555747032befd4ff1a7d0b8097
"
,
"revisionTime"
:
"201
8-11-23T00:00:52
Z"
"revision"
:
"
0868f2647fefb9c3855bb6242aae8aab6d0ddc6d
"
,
"revisionTime"
:
"201
9-01-29T12:17:45
Z"
},
{
"checksumSHA1"
:
"y5pRYZ/NhfEOCFslPEuUZTYXcro="
,
"path"
:
"git.autistici.org/ai3/go-common/tracing"
,
"revision"
:
"
3f5c3e1bd5295686c2f1a4c87da4a1120c88beac
"
,
"revisionTime"
:
"201
8-1
1-2
5
T1
8:36:57
Z"
"revision"
:
"
0868f2647fefb9c3855bb6242aae8aab6d0ddc6d
"
,
"revisionTime"
:
"201
9-0
1-2
9
T1
2:17:45
Z"
},
{
"checksumSHA1"
:
"R18oCPkWjuPqDxPgKvG1KhiSJns="
,
"path"
:
"git.autistici.org/ai3/go-common/unix"
,
"revision"
:
"
be955ddc61cf2c555747032befd4ff1a7d0b8097
"
,
"revisionTime"
:
"201
8-11-23T00:00:52
Z"
"revision"
:
"
0868f2647fefb9c3855bb6242aae8aab6d0ddc6d
"
,
"revisionTime"
:
"201
9-01-29T12:17:45
Z"
},
{
"checksumSHA1"
:
"NtTOmajRf6xh0mkVSm18L70ncl0="
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment