Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DBE-DS-Group1-WS24
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robin Leber
DBE-DS-Group1-WS24
Commits
0fe8f5c0
Commit
0fe8f5c0
authored
1 year ago
by
Robin Leber
Browse files
Options
Downloads
Patches
Plain Diff
ring formation and getting neighbour
(from slides)
parent
9d330f82
No related branches found
No related tags found
1 merge request
!2
leader election und heartbeat
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
voting.py
+29
-0
29 additions, 0 deletions
voting.py
with
29 additions
and
0 deletions
voting.py
0 → 100644
+
29
−
0
View file @
0fe8f5c0
import
socket
def
form_ring
(
members
):
sorted_binary_ring
=
sorted
([
socket
.
inet_aton
(
member
)
for
member
in
members
])
sorted_ip_ring
=
[
socket
.
inet_ntoa
(
node
)
for
node
in
sorted_binary_ring
]
return
sorted_ip_ring
members
=
[
'
192.168.0.1
'
,
'
130.234.204.2
'
,
'
130.234.203.2
'
,
'
130.234.204.1
'
,
'
182.4.3.111
'
]
ring
=
form_ring
(
members
)
print
(
ring
)
def
get_neighbour
(
ring
,
current_node_ip
,
direction
=
'
left
'
):
current_node_index
=
ring
.
index
(
current_node_ip
)
if
current_node_ip
in
ring
else
-
1
if
current_node_index
!=
-
1
:
if
direction
==
'
left
'
:
if
current_node_index
+
1
==
len
(
ring
):
return
ring
[
0
]
else
:
return
ring
[
current_node_index
+
1
]
else
:
if
current_node_index
==
0
:
return
ring
[
len
(
ring
)
-
1
]
else
:
return
ring
[
current_node_index
-
1
]
else
:
return
None
neighbour
=
get_neighbour
(
ring
,
'
130.234.204.2
'
,
'
rigth
'
)
print
(
neighbour
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment