Add API endpoint to return inbound and outbound connections
This commit is contained in:
parent
eebbcf79d1
commit
e6ecaa5e7d
28
src/api.py
28
src/api.py
|
@ -91,6 +91,7 @@ from bmconfigparser import config
|
|||
from debug import logger
|
||||
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure, sql_ready
|
||||
from inventory import Inventory
|
||||
from network import BMConnectionPool
|
||||
from network.threads import StoppableThread
|
||||
from six.moves import queue
|
||||
from version import softwareVersion
|
||||
|
@ -1441,6 +1442,33 @@ class BMRPCDispatcher(object):
|
|||
'softwareVersion': softwareVersion
|
||||
}
|
||||
|
||||
@command('listConnections')
|
||||
def HandleListConnections(self):
|
||||
"""
|
||||
Returns bitmessage connection information as dict with keys *inbound,
|
||||
*outbound.
|
||||
"""
|
||||
inboundConnections = []
|
||||
outboundConnections = []
|
||||
for i in BMConnectionPool().inboundConnections.values():
|
||||
inboundConnections.append({
|
||||
'host': i.destination.host,
|
||||
'port': i.destination.port,
|
||||
'fullyEstablished': i.fullyEstablished,
|
||||
'userAgent': str(i.userAgent)
|
||||
})
|
||||
for i in BMConnectionPool().outboundConnections.values():
|
||||
outboundConnections.append({
|
||||
'host': i.destination.host,
|
||||
'port': i.destination.port,
|
||||
'fullyEstablished': i.fullyEstablished,
|
||||
'userAgent': str(i.userAgent)
|
||||
})
|
||||
return {
|
||||
'inbound': inboundConnections,
|
||||
'outbound': outboundConnections
|
||||
}
|
||||
|
||||
@command('helloWorld')
|
||||
def HandleHelloWorld(self, a, b):
|
||||
"""Test two string params"""
|
||||
|
|
|
@ -157,6 +157,12 @@ class TestAPI(TestAPIProto):
|
|||
else:
|
||||
self.assertGreater(status["networkConnections"], 0)
|
||||
|
||||
def test_listconnections_consistency(self):
|
||||
"""Checking the return of API command 'listConnections'"""
|
||||
result = json.loads(self.api.listConnections())
|
||||
self.assertGreaterEqual(len(result["inbound"]), 0)
|
||||
self.assertGreaterEqual(len(result["outbound"]), 0)
|
||||
|
||||
def test_list_addresses(self):
|
||||
"""Checking the return of API command 'listAddresses'"""
|
||||
self.assertEqual(
|
||||
|
|
Reference in New Issue
Block a user