2020-09-06 06:50:23 +00:00
|
|
|
# internal imports
|
|
|
|
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..')))
|
|
|
|
from komrade import *
|
2020-09-06 19:41:17 +00:00
|
|
|
from komrade.backend import *
|
2020-09-06 06:50:23 +00:00
|
|
|
|
|
|
|
### ACTUAL PHONE CONNECTIONS
|
2020-09-06 19:24:36 +00:00
|
|
|
class TheTelephone(Operator):
|
2020-09-06 06:50:23 +00:00
|
|
|
"""
|
|
|
|
API client class for Caller to interact with The Operator.
|
|
|
|
"""
|
2020-09-07 17:27:46 +00:00
|
|
|
def __init__(self, caller=None):
|
|
|
|
global OPERATOR_KEYCHAIN,TELEPHONE_KEYCHAIN
|
2020-09-07 17:50:58 +00:00
|
|
|
print('OP???',OPERATOR_KEYCHAIN)
|
|
|
|
print('PH???',TELEPHONE_KEYCHAIN)
|
|
|
|
|
2020-09-06 19:24:36 +00:00
|
|
|
super().__init__(
|
|
|
|
name=TELEPHONE_NAME,
|
|
|
|
path_crypt_keys=PATH_CRYPT_CA_KEYS,
|
|
|
|
path_crypt_data=PATH_CRYPT_CA_KEYS
|
|
|
|
)
|
2020-09-07 17:50:58 +00:00
|
|
|
|
|
|
|
if not TELEPHONE_KEYCHAIN or not OPERATOR_KEYCHAIN:
|
|
|
|
OPERATOR_KEYCHAIN,TELEPHONE_KEYCHAIN = connect_phonelines()
|
|
|
|
|
|
|
|
print('OP2???',OPERATOR_KEYCHAIN)
|
|
|
|
print('PH2???',TELEPHONE_KEYCHAIN)
|
|
|
|
|
2020-09-06 22:40:53 +00:00
|
|
|
self.caller=caller
|
2020-09-07 17:50:58 +00:00
|
|
|
self._keychain = TELEPHONE_KEYCHAIN
|
|
|
|
print(type(self._keychain), self._keychain)
|
|
|
|
|
2020-09-06 06:50:23 +00:00
|
|
|
|
2020-09-07 21:29:02 +00:00
|
|
|
def send_and_receive(self,msg_b64_str_esc):
|
|
|
|
URL = OPERATOR_API_URL + msg_b64_str_esc + '/'
|
2020-09-06 06:50:23 +00:00
|
|
|
self.log("DIALING THE OPERATOR:",URL)
|
2020-09-07 21:29:02 +00:00
|
|
|
ringring=komrade_request(URL)
|
|
|
|
if ringring.status_code==200:
|
|
|
|
um_yes_hello = ringring.text
|
|
|
|
return self.answer_phone(um_yes_hello,
|
|
|
|
from_phone=self.op,
|
|
|
|
to_phone=self
|
|
|
|
)
|
2020-09-07 07:46:58 +00:00
|
|
|
else:
|
2020-09-07 21:29:02 +00:00
|
|
|
self.log('!! error in request',ringring.status_code,ringring.text)
|
2020-09-07 07:46:58 +00:00
|
|
|
return None
|
2020-09-07 11:23:10 +00:00
|
|
|
|
2020-09-07 21:29:02 +00:00
|
|
|
def ring_ring(self,
|
2020-09-07 20:00:21 +00:00
|
|
|
from_caller=None,
|
|
|
|
to_caller=None,
|
|
|
|
json_phone2phone={},
|
|
|
|
json_caller2phone={}, # (person) -> operator or operator -> (person)
|
|
|
|
json_caller2caller={}):
|
2020-09-07 19:26:58 +00:00
|
|
|
|
2020-09-07 21:29:02 +00:00
|
|
|
encr_msg_to_send = super().ring_ring(
|
2020-09-07 20:00:21 +00:00
|
|
|
from_phone=self,
|
|
|
|
to_phone=self.op,
|
|
|
|
from_caller=from_caller,
|
|
|
|
to_caller=to_caller,
|
2020-09-07 21:14:33 +00:00
|
|
|
json_phone2phone=json_phone2phone,
|
2020-09-07 20:00:21 +00:00
|
|
|
json_caller2phone=json_caller2phone, # (person) -> operator
|
|
|
|
json_caller2caller=json_caller2caller)
|
|
|
|
|
2020-09-07 21:29:02 +00:00
|
|
|
return self.send_and_receive(encr_msg_to_send)
|
2020-09-07 19:26:58 +00:00
|
|
|
|
2020-09-06 06:50:23 +00:00
|
|
|
|
|
|
|
def test_call():
|
2020-09-06 19:59:14 +00:00
|
|
|
caller = Caller('marx33') #Caller('marx')
|
2020-09-06 06:50:23 +00:00
|
|
|
# caller.boot(create=True)
|
|
|
|
# print(caller.keychain())
|
2020-09-06 19:59:14 +00:00
|
|
|
# phone = TheTelephone()
|
2020-09-06 08:39:31 +00:00
|
|
|
# req_json = {'_route':'forge_new_keys','name':name, 'pubkey_is_public':pubkey_is_public}}
|
|
|
|
# req_json_s = jsonify(req_json)
|
|
|
|
# res = phone.req({'forge_new_keys':{'name':'marx', 'pubkey_is_public':True}})
|
|
|
|
# print(res)
|
2020-09-07 07:41:17 +00:00
|
|
|
# asyncio.run(caller.get_new_keys())
|
2020-09-07 20:11:35 +00:00
|
|
|
x=caller.get_new_keys(passphrase='1869')
|
2020-09-06 06:50:23 +00:00
|
|
|
|
2020-09-07 07:46:58 +00:00
|
|
|
print('YEAH COOL',x)
|
2020-09-06 11:48:35 +00:00
|
|
|
|
2020-09-06 06:50:23 +00:00
|
|
|
## main
|
|
|
|
if __name__=='__main__': test_call()
|