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
cf0e86e9
Commit
cf0e86e9
authored
Dec 24, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 优化tranport
parent
0034e370
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
26 deletions
+40
-26
connection.py
coco/connection.py
+2
-2
models.py
coco/models.py
+11
-1
sshd.py
coco/sshd.py
+27
-23
No files found.
coco/connection.py
View file @
cf0e86e9
...
...
@@ -54,7 +54,7 @@ class SSHConnection:
asset
.
ip
,
port
=
asset
.
port
,
username
=
system_user
.
username
,
password
=
system_user
.
password
,
pkey
=
system_user
.
private_key
,
timeout
=
config
[
'SSH_TIMEOUT'
],
compress
=
Tru
e
,
auth_timeout
=
config
[
'SSH_TIMEOUT'
],
compress
=
Fals
e
,
auth_timeout
=
config
[
'SSH_TIMEOUT'
],
look_for_keys
=
False
,
sock
=
sock
)
except
paramiko
.
AuthenticationException
:
...
...
@@ -62,7 +62,7 @@ class SSHConnection:
ssh
.
connect
(
asset
.
ip
,
port
=
asset
.
port
,
username
=
system_user
.
username
,
password
=
system_user
.
password
,
timeout
=
config
[
'SSH_TIMEOUT'
],
compress
=
Tru
e
,
auth_timeout
=
config
[
'SSH_TIMEOUT'
],
compress
=
Fals
e
,
auth_timeout
=
config
[
'SSH_TIMEOUT'
],
look_for_keys
=
False
,
sock
=
sock
,
allow_agent
=
False
,
)
transport
=
ssh
.
get_transport
()
...
...
coco/models.py
View file @
cf0e86e9
...
...
@@ -59,6 +59,7 @@ class Connection(object):
client
.
close
()
self
.
__class__
.
clients_num
-=
1
del
self
.
clients
[
tid
]
del
client
logger
.
info
(
"Client {} leave, total {} now"
.
format
(
client
,
self
.
__class__
.
clients_num
))
...
...
@@ -80,8 +81,11 @@ class Connection(object):
@classmethod
def
remove_connection
(
cls
,
cid
):
connection
=
cls
.
get_connection
(
cid
)
if
not
connection
:
return
connection
.
close
()
del
cls
.
connections
[
cid
]
del
connection
@classmethod
def
get_connection
(
cls
,
cid
):
...
...
@@ -134,7 +138,9 @@ class Client(object):
def
close
(
self
):
logger
.
info
(
"Client {} close"
.
format
(
self
))
return
self
.
chan
.
close
()
self
.
chan
.
close
()
self
.
chan
=
None
return
def
__getattr__
(
self
,
item
):
return
getattr
(
self
.
chan
,
item
)
...
...
@@ -343,6 +349,7 @@ class BaseServer(object):
logger
.
info
(
"Closed server {}"
.
format
(
self
))
self
.
r_input_output_data_filter
(
b
''
)
self
.
chan
.
close
()
self
.
chan
=
None
def
__getattr__
(
self
,
item
):
return
getattr
(
self
.
chan
,
item
)
...
...
@@ -379,6 +386,9 @@ class Server(BaseServer):
def
close
(
self
):
super
(
Server
,
self
)
.
close
()
self
.
chan
.
transport
.
close
()
self
.
chan
.
transport
=
None
self
.
chan
=
None
logger
.
debug
(
"Backend server closed"
)
if
self
.
sock
:
self
.
sock
.
transport
.
close
()
...
...
coco/sshd.py
View file @
cf0e86e9
...
...
@@ -77,31 +77,33 @@ class SSHServer:
server
=
SSHInterface
(
connection
)
try
:
transport
.
start_server
(
server
=
server
)
while
transport
.
is_active
():
chan
=
transport
.
accept
()
server
.
event
.
wait
(
5
)
if
chan
is
None
:
continue
if
not
server
.
event
.
is_set
():
logger
.
warning
(
"Client not request invalid, exiting"
)
sock
.
close
()
continue
else
:
server
.
event
.
clear
()
client
=
connection
.
clients
.
get
(
chan
.
get_id
())
client
.
chan
=
chan
t
=
threading
.
Thread
(
target
=
self
.
dispatch
,
args
=
(
client
,))
t
.
daemon
=
True
t
.
start
()
transport
.
close
()
del
transport
except
paramiko
.
SSHException
:
logger
.
warning
(
"SSH negotiation failed"
)
return
except
EOFError
as
e
:
logger
.
warning
(
"Handle EOF Error: {}"
.
format
(
e
))
return
while
transport
.
is_active
():
chan
=
transport
.
accept
()
server
.
event
.
wait
(
5
)
if
chan
is
None
:
continue
if
not
server
.
event
.
is_set
():
logger
.
warning
(
"Client not request invalid, exiting"
)
sock
.
close
()
return
else
:
server
.
event
.
clear
()
client
=
connection
.
clients
.
get
(
chan
.
get_id
())
client
.
chan
=
chan
t
=
threading
.
Thread
(
target
=
self
.
dispatch
,
args
=
(
client
,))
t
.
daemon
=
True
t
.
start
()
Connection
.
remove_connection
(
connection
.
id
)
finally
:
Connection
.
remove_connection
(
connection
.
id
)
del
connection
@staticmethod
def
dispatch
(
client
):
...
...
@@ -114,8 +116,10 @@ class SSHServer:
InteractiveServer
(
client
)
.
interact
()
except
IndexError
as
e
:
logger
.
error
(
"Unexpected error occur: {}"
.
format
(
e
))
connection
=
Connection
.
get_connection
(
client
.
connection_id
)
connection
.
remove_client
(
client
.
id
)
finally
:
connection
=
Connection
.
get_connection
(
client
.
connection_id
)
connection
.
remove_client
(
client
.
id
)
del
client
elif
chan_type
==
'subsystem'
:
pass
else
:
...
...
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