Cleanup remaining contextvar
Remove remaining context vars Fix minor formatting Rename bumper.py to run_bumper.py to remove conflict with module name
This commit is contained in:
parent
a1ff95cc23
commit
5efd5112a2
7 changed files with 165 additions and 120 deletions
1
Pipfile
1
Pipfile
|
|
@ -14,6 +14,7 @@ black = "*"
|
|||
nose = "*"
|
||||
coverage = "*"
|
||||
mock = "*"
|
||||
pylint = "*"
|
||||
|
||||
[pipenv]
|
||||
allow_prereleases = true
|
||||
|
|
|
|||
142
Pipfile.lock
generated
142
Pipfile.lock
generated
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "4119ce02f0331e2eae79e97097a00614ec5fb641345868b4cac63f7dd6127a32"
|
||||
"sha256": "f6a2679f2c348e81b120bfa9d06f544ed25c1fcea44d94c419e6af514579fdee"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
|
|
@ -127,20 +127,20 @@
|
|||
},
|
||||
"pyyaml": {
|
||||
"hashes": [
|
||||
"sha256:544a0050e76e9b60751c58617fa28c253ad5d23af2e5f0b1c250390bf90bb0df",
|
||||
"sha256:594bf80477a58b6fd53e8b3f24ccf965c25eeeb6e05e4b1fb18c82c2d2090603",
|
||||
"sha256:75e20ca689d0a2bf0c84f0e2028cc68ebef34b213fa66d73c410c53f870c49f4",
|
||||
"sha256:994da68a1dc1050f290f8017f044172360b608c0f2562b47645ecc69d7a61c0a",
|
||||
"sha256:ad902e00088c50bdced94a57b819c24fdadaeaed5494df7a9a67d63774f210fd",
|
||||
"sha256:b11aff75875ffc73541c4e4b1ac2f5e21717c1fc4396238943b9a44d962e74e1",
|
||||
"sha256:bc733b5a9047c3e4848c0e80eeacfa6a799139242606410260c5450d665ea58c",
|
||||
"sha256:d960c68931b96bb215f385baa8ef867b8ebac66af60fa06cc1008f963848c7ad",
|
||||
"sha256:dd461c04e6a91e4eef7d5b75c1fc1c7013d3f8d354033b16526baadddd524079",
|
||||
"sha256:e4d6b5d6218a06f3141189d75c93876dd525a6d15f1b00ef4f274726c93719f1",
|
||||
"sha256:f3c386fa12415bde8a0162745c4badf98fe171c6dfd67e54831f05ec88feeebb"
|
||||
"sha256:1adecc22f88d38052fb787d959f003811ca858b799590a5eaa70e63dca50308c",
|
||||
"sha256:436bc774ecf7c103814098159fbb84c2715d25980175292c648f2da143909f95",
|
||||
"sha256:460a5a4248763f6f37ea225d19d5c205677d8d525f6a83357ca622ed541830c2",
|
||||
"sha256:5a22a9c84653debfbf198d02fe592c176ea548cccce47553f35f466e15cf2fd4",
|
||||
"sha256:7a5d3f26b89d688db27822343dfa25c599627bc92093e788956372285c6298ad",
|
||||
"sha256:9372b04a02080752d9e6f990179a4ab840227c6e2ce15b95e1278456664cf2ba",
|
||||
"sha256:a5dcbebee834eaddf3fa7366316b880ff4062e4bcc9787b78c7fbb4a26ff2dd1",
|
||||
"sha256:aee5bab92a176e7cd034e57f46e9df9a9862a71f8f37cad167c6fc74c65f5b4e",
|
||||
"sha256:c51f642898c0bacd335fc119da60baae0824f2cde95b0330b56c0553439f0673",
|
||||
"sha256:c68ea4d3ba1705da1e0d85da6684ac657912679a649e8868bd850d2c299cce13",
|
||||
"sha256:e23d0cc5299223dcc37885dae624f382297717e459ea24053709675a976a3e19"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==5.1b5"
|
||||
"version": "==5.1"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
|
|
@ -151,11 +151,11 @@
|
|||
},
|
||||
"tinydb": {
|
||||
"hashes": [
|
||||
"sha256:24b3d4a9611e9953fd57caf063ede6d20abfa0886289fa251f5933082c605dca",
|
||||
"sha256:54f6b52fc9bc8378ea29b60e8d93c58f0f4b580a0a3b345810fbc2375baa7655"
|
||||
"sha256:260b1f69168a24518af63f0270c72dc026476607016a0105aef6a966d8d2fbdc",
|
||||
"sha256:a05c4c81e6e867c4f8a2e51c5236d0d897019aa5e9296f5947455b0bdd3c519d"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.12.2"
|
||||
"version": "==3.13.0"
|
||||
},
|
||||
"transitions": {
|
||||
"hashes": [
|
||||
|
|
@ -215,6 +215,13 @@
|
|||
],
|
||||
"version": "==1.4.3"
|
||||
},
|
||||
"astroid": {
|
||||
"hashes": [
|
||||
"sha256:6560e1e1749f68c64a4b5dee4e091fce798d2f0d84ebe638cf0e0585a343acf4",
|
||||
"sha256:b65db1bbaac9f9f4d190199bb8680af6f6f84fd3769a5ea883df8a91fe68b4c4"
|
||||
],
|
||||
"version": "==2.2.5"
|
||||
},
|
||||
"attrs": {
|
||||
"hashes": [
|
||||
"sha256:69c0dbf2ed392de1cb5ec704444b08a5ef81680a61cb899dc08127123af36a79",
|
||||
|
|
@ -224,11 +231,11 @@
|
|||
},
|
||||
"black": {
|
||||
"hashes": [
|
||||
"sha256:817243426042db1d36617910df579a54f1afd659adb96fc5032fcf4b36209739",
|
||||
"sha256:e030a9a28f542debc08acceb273f228ac422798e5215ba2a791a6ddeaaca22a5"
|
||||
"sha256:09a9dcb7c46ed496a9850b76e4e825d6049ecd38b611f1224857a79bd985a8cf",
|
||||
"sha256:68950ffd4d9169716bcb8719a56c07a2f4485354fec061cdd5910aa07369731c"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==18.9b0"
|
||||
"version": "==19.3b0"
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
|
|
@ -237,6 +244,14 @@
|
|||
],
|
||||
"version": "==7.0"
|
||||
},
|
||||
"colorama": {
|
||||
"hashes": [
|
||||
"sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d",
|
||||
"sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48"
|
||||
],
|
||||
"markers": "sys_platform == 'win32'",
|
||||
"version": "==0.4.1"
|
||||
},
|
||||
"coverage": {
|
||||
"hashes": [
|
||||
"sha256:029c69deaeeeae1b15bc6c59f0ffa28aa8473721c614a23f2c2976dec245cd12",
|
||||
|
|
@ -272,6 +287,55 @@
|
|||
"index": "pypi",
|
||||
"version": "==5.0a4"
|
||||
},
|
||||
"isort": {
|
||||
"hashes": [
|
||||
"sha256:18c796c2cd35eb1a1d3f012a214a542790a1aed95e29768bdcb9f2197eccbd0b",
|
||||
"sha256:96151fca2c6e736503981896495d344781b60d18bfda78dc11b290c6125ebdb6"
|
||||
],
|
||||
"version": "==4.3.15"
|
||||
},
|
||||
"lazy-object-proxy": {
|
||||
"hashes": [
|
||||
"sha256:0ce34342b419bd8f018e6666bfef729aec3edf62345a53b537a4dcc115746a33",
|
||||
"sha256:1b668120716eb7ee21d8a38815e5eb3bb8211117d9a90b0f8e21722c0758cc39",
|
||||
"sha256:209615b0fe4624d79e50220ce3310ca1a9445fd8e6d3572a896e7f9146bbf019",
|
||||
"sha256:27bf62cb2b1a2068d443ff7097ee33393f8483b570b475db8ebf7e1cba64f088",
|
||||
"sha256:27ea6fd1c02dcc78172a82fc37fcc0992a94e4cecf53cb6d73f11749825bd98b",
|
||||
"sha256:2c1b21b44ac9beb0fc848d3993924147ba45c4ebc24be19825e57aabbe74a99e",
|
||||
"sha256:2df72ab12046a3496a92476020a1a0abf78b2a7db9ff4dc2036b8dd980203ae6",
|
||||
"sha256:320ffd3de9699d3892048baee45ebfbbf9388a7d65d832d7e580243ade426d2b",
|
||||
"sha256:50e3b9a464d5d08cc5227413db0d1c4707b6172e4d4d915c1c70e4de0bbff1f5",
|
||||
"sha256:5276db7ff62bb7b52f77f1f51ed58850e315154249aceb42e7f4c611f0f847ff",
|
||||
"sha256:61a6cf00dcb1a7f0c773ed4acc509cb636af2d6337a08f362413c76b2b47a8dd",
|
||||
"sha256:6ae6c4cb59f199d8827c5a07546b2ab7e85d262acaccaacd49b62f53f7c456f7",
|
||||
"sha256:7661d401d60d8bf15bb5da39e4dd72f5d764c5aff5a86ef52a042506e3e970ff",
|
||||
"sha256:7bd527f36a605c914efca5d3d014170b2cb184723e423d26b1fb2fd9108e264d",
|
||||
"sha256:7cb54db3535c8686ea12e9535eb087d32421184eacc6939ef15ef50f83a5e7e2",
|
||||
"sha256:7f3a2d740291f7f2c111d86a1c4851b70fb000a6c8883a59660d95ad57b9df35",
|
||||
"sha256:81304b7d8e9c824d058087dcb89144842c8e0dea6d281c031f59f0acf66963d4",
|
||||
"sha256:933947e8b4fbe617a51528b09851685138b49d511af0b6c0da2539115d6d4514",
|
||||
"sha256:94223d7f060301b3a8c09c9b3bc3294b56b2188e7d8179c762a1cda72c979252",
|
||||
"sha256:ab3ca49afcb47058393b0122428358d2fbe0408cf99f1b58b295cfeb4ed39109",
|
||||
"sha256:bd6292f565ca46dee4e737ebcc20742e3b5be2b01556dafe169f6c65d088875f",
|
||||
"sha256:c0e2945ebf5b6eb32848e9bd6f850f558722caf7ae9427c9fff8e0ea7b185a2f",
|
||||
"sha256:cb924aa3e4a3fb644d0c463cad5bc2572649a6a3f68a7f8e4fbe44aaa6d77e4c",
|
||||
"sha256:d0fc7a286feac9077ec52a927fc9fe8fe2fabab95426722be4c953c9a8bede92",
|
||||
"sha256:ddc34786490a6e4ec0a855d401034cbd1242ef186c20d79d2166d6a4bd449577",
|
||||
"sha256:e34b155e36fa9da7e1b7c738ed7767fc9491a62ec6af70fe9da4a057759edc2d",
|
||||
"sha256:e5b9e8f6bda48460b7b143c3821b21b452cb3a835e6bbd5dd33aa0c8d3f5137d",
|
||||
"sha256:e81ebf6c5ee9684be8f2c87563880f93eedd56dd2b6146d8a725b50b7e5adb0f",
|
||||
"sha256:eb91be369f945f10d3a49f5f9be8b3d0b93a4c2be8f8a5b83b0571b8123e0a7a",
|
||||
"sha256:f460d1ceb0e4a5dcb2a652db0904224f367c9b3c1470d5a7683c0480e582468b"
|
||||
],
|
||||
"version": "==1.3.1"
|
||||
},
|
||||
"mccabe": {
|
||||
"hashes": [
|
||||
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
|
||||
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
|
||||
],
|
||||
"version": "==0.6.1"
|
||||
},
|
||||
"mock": {
|
||||
"hashes": [
|
||||
"sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1",
|
||||
|
|
@ -296,6 +360,14 @@
|
|||
],
|
||||
"version": "==5.1.3"
|
||||
},
|
||||
"pylint": {
|
||||
"hashes": [
|
||||
"sha256:5d77031694a5fb97ea95e828c8d10fc770a1df6eb3906067aaed42201a8a6a09",
|
||||
"sha256:723e3db49555abaf9bf79dc474c6b9e2935ad82230b10c1138a71ea41ac0fff1"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.3.1"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
|
||||
|
|
@ -309,6 +381,38 @@
|
|||
"sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e"
|
||||
],
|
||||
"version": "==0.10.0"
|
||||
},
|
||||
"typed-ast": {
|
||||
"hashes": [
|
||||
"sha256:035a54ede6ce1380599b2ce57844c6554666522e376bd111eb940fbc7c3dad23",
|
||||
"sha256:037c35f2741ce3a9ac0d55abfcd119133cbd821fffa4461397718287092d9d15",
|
||||
"sha256:049feae7e9f180b64efacbdc36b3af64a00393a47be22fa9cb6794e68d4e73d3",
|
||||
"sha256:19228f7940beafc1ba21a6e8e070e0b0bfd1457902a3a81709762b8b9039b88d",
|
||||
"sha256:2ea681e91e3550a30c2265d2916f40a5f5d89b59469a20f3bad7d07adee0f7a6",
|
||||
"sha256:3a6b0a78af298d82323660df5497bcea0f0a4a25a0b003afd0ce5af049bd1f60",
|
||||
"sha256:5385da8f3b801014504df0852bf83524599df890387a3c2b17b7caa3d78b1773",
|
||||
"sha256:606d8afa07eef77280c2bf84335e24390055b478392e1975f96286d99d0cb424",
|
||||
"sha256:69245b5b23bbf7fb242c9f8f08493e9ecd7711f063259aefffaeb90595d62287",
|
||||
"sha256:6f6d839ab09830d59b7fa8fb6917023d8cb5498ee1f1dbd82d37db78eb76bc99",
|
||||
"sha256:730888475f5ac0e37c1de4bd05eeb799fdb742697867f524dc8a4cd74bcecc23",
|
||||
"sha256:9819b5162ffc121b9e334923c685b0d0826154e41dfe70b2ede2ce29034c71d8",
|
||||
"sha256:9e60ef9426efab601dd9aa120e4ff560f4461cf8442e9c0a2b92548d52800699",
|
||||
"sha256:af5fbdde0690c7da68e841d7fc2632345d570768ea7406a9434446d7b33b0ee1",
|
||||
"sha256:b64efdbdf3bbb1377562c179f167f3bf301251411eb5ac77dec6b7d32bcda463",
|
||||
"sha256:bac5f444c118aeb456fac1b0b5d14c6a71ea2a42069b09c176f75e9bd4c186f6",
|
||||
"sha256:bda9068aafb73859491e13b99b682bd299c1b5fd50644d697533775828a28ee0",
|
||||
"sha256:d659517ca116e6750101a1326107d3479028c5191f0ecee3c7203c50f5b915b0",
|
||||
"sha256:eddd3fb1f3e0f82e5915a899285a39ee34ce18fd25d89582bc89fc9fb16cd2c6"
|
||||
],
|
||||
"markers": "implementation_name == 'cpython'",
|
||||
"version": "==1.3.1"
|
||||
},
|
||||
"wrapt": {
|
||||
"hashes": [
|
||||
"sha256:4aea003270831cceb8a90ff27c4031da6ead7ec1886023b80ce0dfe0adf61533",
|
||||
"sha256:71ad0a3729a2f29eb25ff0dd6e66fc9768c749ff0c3f8899a6ac35c059f502c1"
|
||||
],
|
||||
"version": "==1.11.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,9 +66,10 @@ def db_get():
|
|||
db = TinyDB(db_file())
|
||||
|
||||
# Will create the tables if they don't exist
|
||||
users_table = db.table("users", cache_size=0)
|
||||
clients_table = db.table("clients", cache_size=0)
|
||||
bots_table = db.table("bots", cache_size=0)
|
||||
db.table("users", cache_size=0)
|
||||
db.table("clients", cache_size=0)
|
||||
db.table("bots", cache_size=0)
|
||||
db.table("tokens", cache_size=0)
|
||||
|
||||
return db
|
||||
|
||||
|
|
|
|||
|
|
@ -42,11 +42,13 @@ class ConfServer:
|
|||
self.usessl = usessl
|
||||
self.address = address
|
||||
self.confthread = None
|
||||
self.run_async = False
|
||||
self.app = None
|
||||
|
||||
def run(self, run_async=False):
|
||||
try:
|
||||
if run_async:
|
||||
self.run_async = True
|
||||
confserverlog.debug("Starting ConfServer Thread: 1")
|
||||
self.confthread = Thread(
|
||||
name="ConfServer_{}_Thread".format(self.address[1]),
|
||||
|
|
@ -624,6 +626,7 @@ class ConfServer:
|
|||
async def handle_devmanager_botcommand(self, request):
|
||||
try:
|
||||
json_body = json.loads(await request.text())
|
||||
confserverlog.debug("BotCommand: {}".format(json_body))
|
||||
randomid = "".join(random.sample(string.ascii_letters, 6))
|
||||
|
||||
if "toId" in json_body: # Its a command
|
||||
|
|
@ -659,8 +662,8 @@ class ConfServer:
|
|||
if self.run_async:
|
||||
self.confthread.join()
|
||||
else:
|
||||
self.confthread.disconnect()
|
||||
|
||||
self.app.shutdown()
|
||||
|
||||
except Exception as e:
|
||||
confserverlog.exception("{}".format(e))
|
||||
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ class MQTTHelperBot:
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
address,
|
||||
bumper_bots=contextvars.ContextVar,
|
||||
bumper_clients=contextvars.ContextVar,
|
||||
address
|
||||
):
|
||||
self.address = address
|
||||
self.client_id = "helper1@bumper/helper1"
|
||||
|
|
@ -56,7 +54,7 @@ class MQTTHelperBot:
|
|||
self.helperthread.start()
|
||||
|
||||
else:
|
||||
self.run_helperbot()
|
||||
self.run_helperbot(asyncio.get_event_loop())
|
||||
|
||||
def run_helperbot(self, loop):
|
||||
logging.info("Starting MQTT HelperBot")
|
||||
|
|
@ -176,10 +174,7 @@ class MQTTHelperBot:
|
|||
|
||||
|
||||
class MQTTServer:
|
||||
default_config = {}
|
||||
bumper_users = []
|
||||
bumper_clients = []
|
||||
bumper_bots = []
|
||||
default_config = {}
|
||||
|
||||
async def broker_coro(self):
|
||||
try:
|
||||
|
|
@ -198,27 +193,13 @@ class MQTTServer:
|
|||
except Exception as e:
|
||||
mqttserverlog.exception("{}".format(e))
|
||||
exit(1)
|
||||
|
||||
async def active_bot_listing(self):
|
||||
try:
|
||||
while True:
|
||||
await asyncio.sleep(5)
|
||||
mqttserverlog.debug("connected bots - %s" % self.bumper_bots.get())
|
||||
|
||||
except Exception as e:
|
||||
mqttserverlog.exception("{}".format(e))
|
||||
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
address,
|
||||
bumper_users=contextvars.ContextVar,
|
||||
bumper_bots=contextvars.ContextVar,
|
||||
bumper_clients=contextvars.ContextVar,
|
||||
address
|
||||
):
|
||||
try:
|
||||
self.bumper_users = bumper_users
|
||||
self.bumper_bots = bumper_bots
|
||||
self.bumper_clients = bumper_clients
|
||||
try:
|
||||
self.mqttserverthread = None
|
||||
self.address = address
|
||||
|
||||
|
|
@ -249,12 +230,7 @@ class MQTTServer:
|
|||
),
|
||||
"plugins": ["bumper"], # No plugins == no auth
|
||||
},
|
||||
"topic-check": {"enabled": False},
|
||||
"bumper": {
|
||||
"bumper_users": self.bumper_users,
|
||||
"bumper_bots": self.bumper_bots,
|
||||
"bumper_clients": self.bumper_clients,
|
||||
},
|
||||
"topic-check": {"enabled": False},
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -271,7 +247,7 @@ class MQTTServer:
|
|||
self.mqttserverthread.start()
|
||||
|
||||
else:
|
||||
self.run_server()
|
||||
self.run_server(asyncio.get_event_loop())
|
||||
|
||||
def run_server(self, loop):
|
||||
|
||||
|
|
@ -291,7 +267,6 @@ class BumperMQTTServer_Plugin:
|
|||
def __init__(self, context):
|
||||
self.context = context
|
||||
try:
|
||||
self.bumper_config = self.context.config["bumper"]
|
||||
self.auth_config = self.context.config["auth"]
|
||||
|
||||
except KeyError:
|
||||
|
|
@ -317,9 +292,6 @@ class BumperMQTTServer_Plugin:
|
|||
self.context.logger.debug("Authentication success: config allows anonymous")
|
||||
else:
|
||||
try:
|
||||
bumper_users = self.bumper_config["bumper_users"].get()
|
||||
bumper_bots = self.bumper_config["bumper_bots"].get()
|
||||
bumper_clients = self.bumper_config["bumper_clients"].get()
|
||||
session = kwargs.get("session", None)
|
||||
username = session.username
|
||||
password = session.password
|
||||
|
|
@ -387,7 +359,7 @@ class BumperMQTTServer_Plugin:
|
|||
bumper.bot_set_mqtt(bot["did"], True)
|
||||
return
|
||||
|
||||
clientuserid = didsplit[0]
|
||||
#clientuserid = didsplit[0]
|
||||
clientresource = didsplit[1].split("/")[1]
|
||||
client = bumper.client_get(clientresource)
|
||||
if client:
|
||||
|
|
@ -405,7 +377,7 @@ class BumperMQTTServer_Plugin:
|
|||
if bot:
|
||||
bumper.bot_set_mqtt(bot["did"], False)
|
||||
|
||||
clientuserid = didsplit[0]
|
||||
#clientuserid = didsplit[0]
|
||||
clientresource = didsplit[1].split("/")[1]
|
||||
client = bumper.client_get(clientresource)
|
||||
if client:
|
||||
|
|
|
|||
|
|
@ -16,18 +16,9 @@ class XMPPServer:
|
|||
clients = []
|
||||
exit_flag = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
address,
|
||||
bumper_users=contextvars.ContextVar,
|
||||
bumper_bots=contextvars.ContextVar,
|
||||
bumper_clients=contextvars.ContextVar,
|
||||
):
|
||||
def __init__(self, address):
|
||||
# Initialize bot server
|
||||
self.address = address
|
||||
self.bumper_users = bumper_users
|
||||
self.bumper_bots = bumper_bots
|
||||
self.bumper_clients = bumper_clients
|
||||
|
||||
def run(self, run_async=False):
|
||||
if run_async:
|
||||
|
|
@ -82,14 +73,7 @@ class XMPPServer:
|
|||
"starting new client with ip {}".format(client_address[0])
|
||||
)
|
||||
thread_id = uuid.uuid4()
|
||||
client = Client(
|
||||
thread_id,
|
||||
connection,
|
||||
client_address,
|
||||
self.bumper_users,
|
||||
self.bumper_bots,
|
||||
self.bumper_clients,
|
||||
)
|
||||
client = Client(thread_id, connection, client_address)
|
||||
client.setDaemon(True)
|
||||
client.start()
|
||||
self.clients.append(client)
|
||||
|
|
@ -175,15 +159,7 @@ class Client(threading.Thread):
|
|||
BOT = 1
|
||||
CONTROLLER = 2
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
thread_id,
|
||||
connection,
|
||||
client_address,
|
||||
bumper_users=contextvars.ContextVar,
|
||||
bumper_bots=contextvars.ContextVar,
|
||||
bumper_clients=contextvars.ContextVar,
|
||||
):
|
||||
def __init__(self, thread_id, connection, client_address):
|
||||
threading.Thread.__init__(self)
|
||||
self.id = thread_id
|
||||
self.name = "XMPP_Client_{}".format(client_address[0])
|
||||
|
|
@ -197,9 +173,6 @@ class Client(threading.Thread):
|
|||
self.uid = ""
|
||||
self.log_sent_message = False # Set to true to log sends
|
||||
self.log_incoming_data = True # Set to true to log sends
|
||||
self.bumper_users = bumper_users
|
||||
self.bumper_bots = bumper_bots
|
||||
self.bumper_clients = bumper_clients
|
||||
|
||||
xmppserverlog.debug(
|
||||
"new client thread init for client with ip {}".format(self.address)
|
||||
|
|
@ -212,16 +185,20 @@ class Client(threading.Thread):
|
|||
xmppserverlog.debug("send {} - {}".format(self.address, command))
|
||||
self.connection.send(command.encode())
|
||||
|
||||
except OSError as e:
|
||||
xmppserverlog.error("{}".format(e))
|
||||
|
||||
except BrokenPipeError as e:
|
||||
xmppserverlog.error("{}".format(e))
|
||||
self._set_state("DISCONNECT")
|
||||
|
||||
except ConnectionResetError as e:
|
||||
xmppserverlog.error("{}".format(e))
|
||||
# self._set_state('DISCONNECT')
|
||||
self._set_state("DISCONNECT")
|
||||
|
||||
except ConnectionAbortedError as e:
|
||||
xmppserverlog.error("{}".format(e))
|
||||
self._set_state("DISCONNECT")
|
||||
|
||||
except OSError as e:
|
||||
xmppserverlog.error("{}".format(e))
|
||||
|
||||
except Exception as e:
|
||||
xmppserverlog.exception("{}".format(e))
|
||||
|
|
@ -245,7 +222,7 @@ class Client(threading.Thread):
|
|||
def _tag_strip_uri(self, tag):
|
||||
try:
|
||||
if tag[0] == "{":
|
||||
uri, ignore, tag = tag[1:].partition("}")
|
||||
_, _, tag = tag[1:].partition("}")
|
||||
return tag
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -358,7 +335,7 @@ class Client(threading.Thread):
|
|||
and client.state == client.READY
|
||||
):
|
||||
if pingto.lower() in client.bumper_jid.lower():
|
||||
pingsend = '<iq type="result" id="{}" from="{}" to="{}" />'.format(
|
||||
pingstring = '<iq type="result" id="{}" from="{}" to="{}" />'.format(
|
||||
xml.get("id"), pingfrom, pingto
|
||||
)
|
||||
xmppserverlog.debug(
|
||||
|
|
@ -548,7 +525,7 @@ class Client(threading.Thread):
|
|||
and self.type == self.UNKNOWN
|
||||
):
|
||||
xmlauth = xml[0].getchildren()
|
||||
uid = ""
|
||||
# uid = ""
|
||||
password = ""
|
||||
resource = ""
|
||||
for aitem in xmlauth:
|
||||
|
|
@ -566,7 +543,7 @@ class Client(threading.Thread):
|
|||
if not self.uid.startswith("fuid"):
|
||||
|
||||
# Need sample data to see details here
|
||||
bumper.bot_add("", self.uid, "", resource)
|
||||
bumper.bot_add("", self.uid, "", resource, "eco-legacy")
|
||||
xmppserverlog.info("bot authenticated {}".format(self.uid))
|
||||
|
||||
# Client authenticated, move to next state
|
||||
|
|
@ -678,8 +655,6 @@ class Client(threading.Thread):
|
|||
|
||||
def _handle_bind(self, xml):
|
||||
try:
|
||||
bumper_bots = self.bumper_bots.get()
|
||||
bumper_clients = self.bumper_clients.get()
|
||||
|
||||
bot = bumper.bot_get(self.uid)
|
||||
if bot:
|
||||
|
|
|
|||
|
|
@ -26,31 +26,20 @@ def main():
|
|||
if platform.system() == "Darwin": # If a Mac, use 0.0.0.0 for listening
|
||||
listen_host = "0.0.0.0"
|
||||
else:
|
||||
listen_host = socket.gethostbyname(socket.gethostname())
|
||||
# listen_host = "localhost" #Try this if the above doesn't work
|
||||
# listen_host = socket.gethostbyname(socket.gethostname())
|
||||
listen_host = "10.0.1.220" # Try this if the above doesn't work
|
||||
|
||||
|
||||
conf_address_443 = (listen_host, 443)
|
||||
conf_address_8007 = (listen_host, 8007)
|
||||
xmpp_address = (listen_host, 5223)
|
||||
mqtt_address = (listen_host, 8883)
|
||||
|
||||
xmpp_server = bumper.XMPPServer(
|
||||
xmpp_address,
|
||||
bumper_users=bumper.bumper_users_var,
|
||||
bumper_bots=bumper.bumper_bots_var,
|
||||
bumper_clients=bumper.bumper_clients_var,
|
||||
)
|
||||
mqtt_server = bumper.MQTTServer(
|
||||
mqtt_address,
|
||||
bumper_users=bumper.bumper_users_var,
|
||||
bumper_bots=bumper.bumper_bots_var,
|
||||
bumper_clients=bumper.bumper_clients_var,
|
||||
)
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(
|
||||
mqtt_address,
|
||||
bumper_bots=bumper.bumper_bots_var,
|
||||
bumper_clients=bumper.bumper_clients_var,
|
||||
xmpp_address
|
||||
)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(mqtt_address)
|
||||
conf_server = bumper.ConfServer(
|
||||
conf_address_443, usessl=True, helperbot=mqtt_helperbot
|
||||
)
|
||||
|
|
@ -94,7 +83,7 @@ def main():
|
|||
except KeyboardInterrupt:
|
||||
bumper.bumperlog.info("Bumper Exiting - Keyboard Interrupt")
|
||||
print("Bumper Exiting")
|
||||
exit(1)
|
||||
exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Loading…
Add table
Add a link
Reference in a new issue