Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs425_distributed_system_mp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
hangxie2
cs425_distributed_system_mp
Commits
815e0e2d
Commit
815e0e2d
authored
3 years ago
by
Hang
Browse files
Options
Downloads
Patches
Plain Diff
fast push
parent
6e2e1a20
No related branches found
No related tags found
1 merge request
!10
MP3 Log Version Ready
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mp3/server.py
+28
-28
28 additions, 28 deletions
mp3/server.py
with
28 additions
and
28 deletions
mp3/server.py
+
28
−
28
View file @
815e0e2d
...
@@ -460,14 +460,14 @@ def connect_with_all_servers(servers: dict, current_server_id: str, return_value
...
@@ -460,14 +460,14 @@ def connect_with_all_servers(servers: dict, current_server_id: str, return_value
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
host_ip_address
=
SERVER_ID_TO_IP_MAPPING
[
server
[
SERVER_IDENTIFIER
]]
host_ip_address
=
SERVER_ID_TO_IP_MAPPING
[
server
[
SERVER_IDENTIFIER
]]
# server[SERVER_PORT] = SERVERS[CURRENT_SERVER_ID][SERVER_PORT]+1 # todo: to be deleted
# server[SERVER_PORT] = SERVERS[CURRENT_SERVER_ID][SERVER_PORT]+1 # todo: to be deleted
address
=
(
host_ip_address
,
SERVERS
[
server
_id
]
[
ACCEPTING_PEER_PORT
])
address
=
(
host_ip_address
,
server
[
ACCEPTING_PEER_PORT
])
pprint
(
f
"
[connect_with_all_servers] -
{
CURRENT_SERVER_ID
}
is trying to
"
pprint
(
f
"
[connect_with_all_servers] -
{
CURRENT_SERVER_ID
}
is trying to
"
f
"
connect
{
(
host_ip_address
,
SERVERS
[
server
_id
]
[
ACCEPTING_PEER_PORT
])
}
"
)
f
"
connect
{
(
host_ip_address
,
server
[
ACCEPTING_PEER_PORT
])
}
"
)
s
.
connect
(
address
)
s
.
connect
(
address
)
connect_info
[
server_id
]
=
s
connect_info
[
server_id
]
=
s
gprint
(
f
"
[Connect] -
"
gprint
(
f
"
[Connect] -
"
f
"
Connecting to
{
server
[
SERVER_IDENTIFIER
]
}
:
{
host_ip_address
}
:
"
f
"
Connecting to
{
server
[
SERVER_IDENTIFIER
]
}
:
{
host_ip_address
}
:
"
f
"
{
server
[
server_id
][
ACCEPTING_PEER_PORT
]
}
success!
"
)
f
"
{
server
[
ACCEPTING_PEER_PORT
]
}
success!
"
)
except
Exception
:
except
Exception
:
rprint
(
f
"
[Connect] - Connection to
"
rprint
(
f
"
[Connect] - Connection to
"
f
"
{
server
[
SERVER_IDENTIFIER
]
}
failed.
"
f
"
{
server
[
SERVER_IDENTIFIER
]
}
failed.
"
...
@@ -745,31 +745,31 @@ def accepting_peer_servers(SELF_NODE):
...
@@ -745,31 +745,31 @@ def accepting_peer_servers(SELF_NODE):
server
.
close
()
server
.
close
()
def
accepting_connections
(
SELF_NODE
):
#
def accepting_connections(SELF_NODE):
try
:
#
try:
server
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
#
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server
.
bind
((
CURRENT_SERVER_IP
,
CURRENT_SERVER_PORT
))
#
server.bind((CURRENT_SERVER_IP, CURRENT_SERVER_PORT))
server
.
listen
()
#
server.listen()
# print(f"[LISTENING] Server is listening on {ADDR}") # DEBUG
#
# print(f"[LISTENING] Server is listening on {ADDR}") # DEBUG
while
True
:
#
while True:
conn
,
addr
=
server
.
accept
()
#
conn, addr = server.accept()
if
addr
[
0
]
in
SERVERS
.
keys
():
#
if addr[0] in SERVERS.keys():
thread
=
threading
.
Thread
(
target
=
server_handler
,
args
=
[
conn
,
SELF_NODE
])
#
thread = threading.Thread(target=server_handler, args=[conn, SELF_NODE])
gprint
(
#
gprint(
f
'
[accepting_peer_servers] - peer server [
{
addr
}
] connect to server [
{
CURRENT_SERVER_ID
}
] success!
'
)
#
f'[accepting_peer_servers] - peer server [{addr}] connect to server [{CURRENT_SERVER_ID}] success!')
thread
.
start
()
#
thread.start()
else
:
#
else:
thread
=
threading
.
Thread
(
target
=
client_handler
,
args
=
[
conn
,
SELF_NODE
])
#
thread = threading.Thread(target=client_handler, args=[conn, SELF_NODE])
gprint
(
f
'
[accepting_clients] - client [
{
addr
}
] connect to coordinator [
{
CURRENT_SERVER_ID
}
] success!
'
)
#
gprint(f'[accepting_clients] - client [{addr}] connect to coordinator [{CURRENT_SERVER_ID}] success!')
thread
.
start
()
#
thread.start()
# client_send_socket = server.connect(addr)
#
# client_send_socket = server.connect(addr)
# gprint(f'[accepting_peer_servers] - server [{CURRENT_SERVER_ID}] connect to peer server [{addr}] success!')
#
# gprint(f'[accepting_peer_servers] - server [{CURRENT_SERVER_ID}] connect to peer server [{addr}] success!')
# thread = threading.Thread(target=server_handler, args=[conn, SELF_NODE])
#
# thread = threading.Thread(target=server_handler, args=[conn, SELF_NODE])
# thread.start()
#
# thread.start()
except
Exception
as
e
:
#
except Exception as e:
rprint
(
f
"
[ERROR] accepting_peer_servers error:
{
e
.
__class__
.
__name__
}
.
{
e
}
.
{
traceback
.
format_exc
()
}
"
)
#
rprint(f"[ERROR] accepting_peer_servers error:{e.__class__.__name__}.{e}.{traceback.format_exc()}")
finally
:
#
finally:
server
.
close
()
#
server.close()
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
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