Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-routing
Commits
2af3b166
Commit
2af3b166
authored
Feb 12, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(snrouting) replicate Provider, PutValue to multiple remotes
parent
4487bfd5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
supernode/proxy/standard.go
supernode/proxy/standard.go
+10
-0
No files found.
supernode/proxy/standard.go
View file @
2af3b166
...
...
@@ -61,15 +61,25 @@ func (p *standard) HandleStream(s inet.Stream) {
s
.
Close
()
}
const
replicationFactor
=
2
// SendMessage sends message to each remote sequentially (randomized order),
// stopping after the first successful response. If all fail, returns the last
// error.
func
(
px
*
standard
)
SendMessage
(
ctx
context
.
Context
,
m
*
dhtpb
.
Message
)
error
{
var
err
error
var
numSuccesses
int
for
_
,
remote
:=
range
sortedByKey
(
px
.
remoteIDs
,
m
.
GetKey
())
{
if
err
=
px
.
sendMessage
(
ctx
,
m
,
remote
);
err
!=
nil
{
// careful don't re-declare err!
continue
}
numSuccesses
++
switch
m
.
GetType
()
{
case
dhtpb
.
Message_ADD_PROVIDER
,
dhtpb
.
Message_PUT_VALUE
:
if
numSuccesses
<
replicationFactor
{
continue
}
}
return
nil
// success
}
return
err
// NB: returns the last error
...
...
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