komrade update!

posting
quadrismegistus 4 years ago
parent 5b10bf7502
commit bfb12a1253

@ -306,41 +306,67 @@ class KomradeX(Caller):
msg[ROUTE_KEYNAME]=route msg[ROUTE_KEYNAME]=route
return super().ring_ring(msg,caller=self,**y) 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): # def post(self,something,to_name=WORLD_NAME):
self.log('<-',something,to_name) # self.log('<-',something,to_name)
# encryption chain: # # encryption chain:
# me -> world # # me -> world
# me -> op # # me -> op
# op <- me # # op <- me
# op -> others # # op -> others
to_komrade = Komrade(to_name) # to_komrade = Komrade(to_name)
self.log('posting to',to_name,to_komrade,to_komrade.uri) # self.log('posting to',to_name,to_komrade,to_komrade.uri)
# make post data # # make post data
# encrypt # # encrypt
something_encr = SMessage( # something_encr = SMessage(
self.privkey.data, # self.privkey.data,
to_komrade.pubkey.data # to_komrade.pubkey.data
).wrap(something) # ).wrap(something)
# make dict (do not use normal msg_d key names!) # # make dict (do not use normal msg_d key names!)
post_d = { # post_d = {
'post':{ # 'post':{
'from':self.uri, # 'from':self.uri,
'from_name':self.name, # 'from_name':self.name,
'to_name':to_name, # 'to_name':to_name,
'to':to_komrade.uri, # 'to':to_komrade.uri,
'msg':something_encr # 'msg':something_encr
} # }
} # }
self.log('post_d =',post_d) # self.log('post_d =',post_d)
# enclose as message to operator # # enclose as message to operator
self.ring_ring( # self.ring_ring(
post_d, # post_d,
route='post' # route='post'
) # )
def post(self,something):
return self.msg(WORLD_NAME,something)
@ -588,6 +614,7 @@ class KomradeX(Caller):
self.log('->',res) self.log('->',res)
return res return res
def read_msg(self,post_id): def read_msg(self,post_id):
# get post # get post
post_encr = self.crypt_keys.get(post_id,prefix='/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)) # self.log('Operator returning result:',dict_format(res,tab=2))
def fetch_posts(self,msg_to_op):
# get posts by personating world
world = Komrade(WORLD_NAME)
def post(self,msg_to_op): world_inbox_res = world.inbox()
self.log('post <-',msg_to_op.msg_d) if not world_inbox_res.get('success'):
self.log('post data <-',msg_to_op.data) return world_inbox_res
post_d = msg_to_op.data.get('post') world_msgs = world_inbox_res.get('msgs')
self.log('post_d =',post_d)
# encrypt to sender from world
# need to decrypt this first -- it's to World, world_msgs_b = BSEP.join([msg.msg_b for msg in world_msgs])
# which I on the server have access to private key. world_msg_to_sender = Message(
# I need to decrypt and re-encrypt/reroute from_whom=world,
#msg_to_world = Message(post_d) to_whom=msg_to_op.from_whom,
#self.log('msg to world',dict_format(msg_to_world.msg_d)) msg=world_msgs_b
)
# decrypt self.log(world_msg_to_sender,'<- world_msg_to_sender')
encr_txt = post_d.get('msg') # encrypt
txt = SMessage( world_msg_to_sender.encrypt()
Komrade(post_d.get('to_name')).privkey.data, # requires we have this privkey!!! self.log(world_msg_to_sender,'<- world_msg_to_sender encrypted')
Komrade(post_d.get('from_name')).pubkey.data
).unwrap(encr_txt) return world_msg_to_sender.msg_d
self.log('unencr txt',txt)
# normally we'd deliver it to the person # def post1(self,msg_to_op):
# but here we need to deliver it to... # self.log('post <-',msg_to_op.msg_d)
# everyone? # self.log('post data <-',msg_to_op.data)
contacts = sorted([fn.split('.png')[0] for fn in os.listdir(PATH_QRCODES)]) # post_d = msg_to_op.data.get('post')
self.log('contacts =',contacts) # self.log('post_d =',post_d)
# mass send! # # need to decrypt this first -- it's to World,
res = self.mass_deliver_msg(txt,contacts) # # which I on the server have access to private key.
# # I need to decrypt and re-encrypt/reroute
return { # #msg_to_world = Message(post_d)
'status':'Hold your horses.', # #self.log('msg to world',dict_format(msg_to_world.msg_d))
'success':False,
'res_mass_deliver_msg':res # # 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 mass_deliver_msg(self,post_msg_d,contacts):
def do_mass_deliver_msg(contact,post_msg_d=post_msg_d): def do_mass_deliver_msg(contact,post_msg_d=post_msg_d):

Loading…
Cancel
Save