komrade update!

posting
quadrismegistus 4 years ago
parent 5b10bf7502
commit bfb12a1253

@ -306,41 +306,67 @@ class KomradeX(Caller):
msg[ROUTE_KEYNAME]=route
return super().ring_ring(msg,caller=self,**y)
def fetch_posts(self,n=100,only_from=[],not_from=[]):
# already seen?
seen_post_ids = pickle.loads(
self.crypt_keys.get(
'seen_post_ids',
prefix='/cache/'
)
)
# ring operator
res = self.ring_ring(
{
'seen_post_ids':seen_post_ids,
'only_from':only_from,
'not_from':not_from,
'n':n
},
route='fetch_posts'
)
print(fetch_posts,'fetched_posts')
def post(self,something,to_name=WORLD_NAME):
self.log('<-',something,to_name)
# encryption chain:
# me -> world
# me -> op
# op <- me
# op -> others
to_komrade = Komrade(to_name)
self.log('posting to',to_name,to_komrade,to_komrade.uri)
# make post data
# def post(self,something,to_name=WORLD_NAME):
# self.log('<-',something,to_name)
# # encryption chain:
# # me -> world
# # me -> op
# # op <- me
# # op -> others
# to_komrade = Komrade(to_name)
# self.log('posting to',to_name,to_komrade,to_komrade.uri)
# # make post data
# encrypt
something_encr = SMessage(
self.privkey.data,
to_komrade.pubkey.data
).wrap(something)
# make dict (do not use normal msg_d key names!)
post_d = {
'post':{
'from':self.uri,
'from_name':self.name,
'to_name':to_name,
'to':to_komrade.uri,
'msg':something_encr
}
}
self.log('post_d =',post_d)
# enclose as message to operator
self.ring_ring(
post_d,
route='post'
)
# # encrypt
# something_encr = SMessage(
# self.privkey.data,
# to_komrade.pubkey.data
# ).wrap(something)
# # make dict (do not use normal msg_d key names!)
# post_d = {
# 'post':{
# 'from':self.uri,
# 'from_name':self.name,
# 'to_name':to_name,
# 'to':to_komrade.uri,
# 'msg':something_encr
# }
# }
# self.log('post_d =',post_d)
# # enclose as message to operator
# self.ring_ring(
# post_d,
# route='post'
# )
def post(self,something):
return self.msg(WORLD_NAME,something)
@ -588,6 +614,7 @@ class KomradeX(Caller):
self.log('->',res)
return res
def read_msg(self,post_id):
# get post
post_encr = self.crypt_keys.get(post_id,prefix='/post/')

@ -328,44 +328,66 @@ class TheOperator(Operator):
# self.log('Operator returning result:',dict_format(res,tab=2))
def post(self,msg_to_op):
self.log('post <-',msg_to_op.msg_d)
self.log('post data <-',msg_to_op.data)
post_d = msg_to_op.data.get('post')
self.log('post_d =',post_d)
# need to decrypt this first -- it's to World,
# which I on the server have access to private key.
# I need to decrypt and re-encrypt/reroute
#msg_to_world = Message(post_d)
#self.log('msg to world',dict_format(msg_to_world.msg_d))
# decrypt
encr_txt = post_d.get('msg')
txt = SMessage(
Komrade(post_d.get('to_name')).privkey.data, # requires we have this privkey!!!
Komrade(post_d.get('from_name')).pubkey.data
).unwrap(encr_txt)
self.log('unencr txt',txt)
# normally we'd deliver it to the person
# but here we need to deliver it to...
# everyone?
contacts = sorted([fn.split('.png')[0] for fn in os.listdir(PATH_QRCODES)])
self.log('contacts =',contacts)
# mass send!
res = self.mass_deliver_msg(txt,contacts)
return {
'status':'Hold your horses.',
'success':False,
'res_mass_deliver_msg':res
}
def fetch_posts(self,msg_to_op):
# get posts by personating world
world = Komrade(WORLD_NAME)
world_inbox_res = world.inbox()
if not world_inbox_res.get('success'):
return world_inbox_res
world_msgs = world_inbox_res.get('msgs')
# encrypt to sender from world
world_msgs_b = BSEP.join([msg.msg_b for msg in world_msgs])
world_msg_to_sender = Message(
from_whom=world,
to_whom=msg_to_op.from_whom,
msg=world_msgs_b
)
self.log(world_msg_to_sender,'<- world_msg_to_sender')
# encrypt
world_msg_to_sender.encrypt()
self.log(world_msg_to_sender,'<- world_msg_to_sender encrypted')
return world_msg_to_sender.msg_d
# def post1(self,msg_to_op):
# self.log('post <-',msg_to_op.msg_d)
# self.log('post data <-',msg_to_op.data)
# post_d = msg_to_op.data.get('post')
# self.log('post_d =',post_d)
# # need to decrypt this first -- it's to World,
# # which I on the server have access to private key.
# # I need to decrypt and re-encrypt/reroute
# #msg_to_world = Message(post_d)
# #self.log('msg to world',dict_format(msg_to_world.msg_d))
# # decrypt
# encr_txt = post_d.get('msg')
# txt = SMessage(
# Komrade(post_d.get('to_name')).privkey.data, # requires we have this privkey!!!
# Komrade(post_d.get('from_name')).pubkey.data
# ).unwrap(encr_txt)
# self.log('unencr txt',txt)
# post
# # normally we'd deliver it to the person
# # but here we need to deliver it to...
# # everyone?
# contacts = sorted([fn.split('.png')[0] for fn in os.listdir(PATH_QRCODES)])
# self.log('contacts =',contacts)
# # mass send!
# res = self.mass_deliver_msg(txt,contacts)
# return {
# 'status':'Hold your horses.',
# 'success':False,
# 'res_mass_deliver_msg':res
# }
def mass_deliver_msg(self,post_msg_d,contacts):
def do_mass_deliver_msg(contact,post_msg_d=post_msg_d):

Loading…
Cancel
Save