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
b7744b2a
Commit
b7744b2a
authored
10 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix for #141, routing table segmentation
parent
6d8a1d1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
routing/kbucket/table.go
routing/kbucket/table.go
+19
-11
No files found.
routing/kbucket/table.go
View file @
b7744b2a
...
...
@@ -65,18 +65,10 @@ func (rt *RoutingTable) Update(p peer.Peer) peer.Peer {
// Are we past the max bucket size?
if
bucket
.
len
()
>
rt
.
bucketsize
{
// If this bucket is the rightmost bucket, and its full
// we need to split it and create a new bucket
if
bucketID
==
len
(
rt
.
Buckets
)
-
1
{
newBucket
:=
bucket
.
Split
(
bucketID
,
rt
.
local
)
rt
.
Buckets
=
append
(
rt
.
Buckets
,
newBucket
)
if
newBucket
.
len
()
>
rt
.
bucketsize
{
// TODO: This is a very rare and annoying case
panic
(
"Case not handled."
)
}
// If all elements were on left side of split...
if
bucket
.
len
()
>
rt
.
bucketsize
{
return
bucket
.
popBack
()
}
return
rt
.
nextBucket
()
}
else
{
// If the bucket cant split kick out least active node
return
bucket
.
popBack
()
...
...
@@ -91,6 +83,22 @@ func (rt *RoutingTable) Update(p peer.Peer) peer.Peer {
return
nil
}
func
(
rt
*
RoutingTable
)
nextBucket
()
peer
.
Peer
{
bucket
:=
rt
.
Buckets
[
len
(
rt
.
Buckets
)
-
1
]
newBucket
:=
bucket
.
Split
(
len
(
rt
.
Buckets
)
-
1
,
rt
.
local
)
rt
.
Buckets
=
append
(
rt
.
Buckets
,
newBucket
)
if
newBucket
.
len
()
>
rt
.
bucketsize
{
// TODO: This is a very rare and annoying case
return
rt
.
nextBucket
()
}
// If all elements were on left side of split...
if
bucket
.
len
()
>
rt
.
bucketsize
{
return
bucket
.
popBack
()
}
return
nil
}
// A helper struct to sort peers by their distance to the local node
type
peerDistance
struct
{
p
peer
.
Peer
...
...
This diff is collapsed.
Click to expand it.
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