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
Commits
450f21a5
Commit
450f21a5
authored
Feb 02, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(gcr/s) de-duplicate routing records
parent
e2a3c4d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
routing/grandcentral/server.go
routing/grandcentral/server.go
+13
-4
No files found.
routing/grandcentral/server.go
View file @
450f21a5
...
...
@@ -131,16 +131,25 @@ func putRoutingRecord(ds datastore.Datastore, k util.Key, value *dhtpb.Record) e
return
nil
}
func
putRoutingProviders
(
ds
datastore
.
Datastore
,
k
util
.
Key
,
provider
s
[]
*
dhtpb
.
Message_Peer
)
error
{
func
putRoutingProviders
(
ds
datastore
.
Datastore
,
k
util
.
Key
,
newRecord
s
[]
*
dhtpb
.
Message_Peer
)
error
{
log
.
Event
(
context
.
Background
(),
"putRoutingProviders"
,
&
k
)
pkey
:=
datastore
.
KeyWithNamespaces
([]
string
{
"routing"
,
"providers"
,
k
.
String
()})
old
,
err
:=
getRoutingProviders
(
ds
,
k
)
old
Records
,
err
:=
getRoutingProviders
(
ds
,
k
)
if
err
!=
nil
{
return
err
}
providers
=
append
(
providers
,
old
...
)
mergedRecords
:=
make
(
map
[
string
]
*
dhtpb
.
Message_Peer
)
for
_
,
provider
:=
range
oldRecords
{
mergedRecords
[
provider
.
GetId
()]
=
provider
// add original records
}
for
_
,
provider
:=
range
newRecords
{
mergedRecords
[
provider
.
GetId
()]
=
provider
// overwrite old record if new exists
}
var
protomsg
dhtpb
.
Message
protomsg
.
ProviderPeers
=
providers
protomsg
.
ProviderPeers
=
make
([]
*
dhtpb
.
Message_Peer
,
0
,
len
(
mergedRecords
))
for
_
,
provider
:=
range
mergedRecords
{
protomsg
.
ProviderPeers
=
append
(
protomsg
.
ProviderPeers
,
provider
)
}
data
,
err
:=
proto
.
Marshal
(
&
protomsg
)
if
err
!=
nil
{
return
err
...
...
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