Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
coco
Commits
074c6036
Commit
074c6036
authored
Jan 03, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 继续支持多进程
parent
5b05f664
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
13 deletions
+10
-13
sshd.py
coco/sshd.py
+10
-13
No files found.
coco/sshd.py
View file @
074c6036
...
...
@@ -8,19 +8,18 @@ import threading
import
time
import
random
import
multiprocessing
from
multiprocessing.reduction
import
recv_handle
,
send_handle
,
DupFd
from
multiprocessing.reduction
import
recv_handle
,
send_handle
import
paramiko
from
coco
.utils
import
ssh_key_gen
,
get_logger
from
coco
.interface
import
SSHInterface
from
coco
.interactive
import
InteractiveServer
from
coco
.models
import
Connection
from
coco
.sftp
import
SFTPServer
from
coco
.config
import
config
from
.utils
import
ssh_key_gen
,
get_logger
from
.interface
import
SSHInterface
from
.interactive
import
InteractiveServer
from
.models
import
Connection
from
.sftp
import
SFTPServer
from
.config
import
config
logger
=
get_logger
(
__file__
)
current_socks
=
[]
BACKLOG
=
5
...
...
@@ -53,7 +52,7 @@ class SSHServer:
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
True
)
sock
.
bind
((
host
,
port
))
sock
.
listen
(
BACKLOG
)
while
True
:
while
not
self
.
stop_evt
.
is_set
()
:
try
:
client
,
addr
=
sock
.
accept
()
worker
=
random
.
choice
(
workers
)
...
...
@@ -63,7 +62,7 @@ class SSHServer:
def
start_worker
(
self
,
in_p
,
out_p
):
out_p
.
close
()
while
True
:
while
not
self
.
stop_evt
.
is_set
()
:
fd
=
recv_handle
(
in_p
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
fileno
=
fd
)
# print("Recv sock: {}".format(sock))
...
...
@@ -95,12 +94,10 @@ class SSHServer:
server_p
.
join
()
c1
.
close
()
c2
.
close
()
print
(
"Exit"
)
print
(
"Exit
ssh server process
"
)
def
handle_connection
(
self
,
sock
,
addr
):
logger
.
debug
(
"Handle new connection from: {}"
.
format
(
addr
))
time
.
sleep
(
4
)
print
(
"Sock is closed: {} 2"
.
format
(
sock
.
_closed
))
transport
=
paramiko
.
Transport
(
sock
,
gss_kex
=
False
)
try
:
transport
.
load_server_moduli
()
...
...
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