what changed?

pull/20/head
quadrismegistus 4 years ago
parent 303ccee9b9
commit b897f5930d

@ -5,7 +5,7 @@ HORIZONTAL = False #random.choice([True,True,True,False])
FACTOR=1 FACTOR=1
WINDOW_SIZE = (1136*FACTOR,640*FACTOR) if HORIZONTAL else (640*FACTOR,1136*FACTOR) WINDOW_SIZE = (1136*FACTOR,640*FACTOR) if HORIZONTAL else (640*FACTOR,1136*FACTOR)
WINDOW_SIZE=800,800 WINDOW_SIZE=700,700
BG_IMG='assets/bg-brown.png' BG_IMG='assets/bg-brown.png'

@ -368,8 +368,10 @@ class MainApp(MDApp):
async def get_post(self,post_id): async def get_post(self,post_id):
return await self.api.get_post(post_id) return await self.api.get_post(post_id)
async def get_posts(self): async def get_posts(self,uri='/posts/channel/earth'):
data = await self.api.get_posts() self.log(f'app.get_posts(uri={uri} -> ...')
data = await self.api.get_posts(uri)
self.log
newdata=[] newdata=[]
for d in data: for d in data:
@ -382,7 +384,8 @@ class MainApp(MDApp):
return newdata return newdata
async def get_my_posts(self): async def get_my_posts(self):
return await self.api.get_posts('/author/'+self.username) self.log(f'get_my_posts({self.username})')
return await self.get_posts(uri='/posts/author/'+self.username)

@ -35,7 +35,7 @@
pos_hint: {'center_x':0.5} #, 'y':0.5} pos_hint: {'center_x':0.5} #, 'y':0.5}
# height: '100dp' #self.minimum_height # height: '100dp' #self.minimum_height
# width: '100dp' # width: '100dp'
height: '300dp' height: '300sp'
# spacing:'100dp' # spacing:'100dp'
# padding:'100dp' # padding:'100dp'
@ -79,15 +79,17 @@
# pos_hint:(None,None) # pos_hint:(None,None)
pos_hint: {'center_x':0.5, 'center_y':0} pos_hint: {'center_x':0.5, 'center_y':0}
# md_bg_color: 1,1,0,1 # md_bg_color: 1,1,0,1
height: '100dp' #self.minimum_height height: '100sp' #self.minimum_height
# radius:[20,] # radius:[20,]
# border_radius:20 # border_radius:20
# height: self.minimum_height
<PostAuthorAvatar>: <PostAuthorAvatar>:
size_hint:(None,None) size_hint:(None,None)
pos_hint:{'center_x':1,'x':1} pos_hint:{'center_x':1,'x':1}
height:'100sp'
# padding:'10dp' # padding:'10dp'
# canvas: # canvas:
# Color: # Color:
@ -113,6 +115,7 @@
padding: ('10dp','0dp') padding: ('10dp','0dp')
bold: True bold: True
markup: True markup: True
# font_size: '24sp'
<PostTimestampLabel>: <PostTimestampLabel>:
id: post_timestamp_label id: post_timestamp_label
@ -139,14 +142,15 @@
id: post_content id: post_content
text: '' text: ''
pos_hint: {'center_y':1} pos_hint: {'center_y':1}
font_size:'58dp' font_size:'13sp'
font_style:'H5' # font_style:'H5'
#font_name: "Strengthen" #font_name: "Strengthen"
# height: '400' # height: '400'
size_hint_y: None size_hint_y: 1
text_color:rgb(*COLOR_TEXT) text_color:rgb(*COLOR_TEXT)
theme_text_color: 'Custom' theme_text_color: 'Custom'
halign: 'left' halign: 'left'
# adaptive_height: True
<PostScrollView>: <PostScrollView>:
size_hint: (1,None) size_hint: (1,None)
@ -157,7 +161,10 @@
id: post id: post
orientation: "vertical" orientation: "vertical"
padding: "20dp" padding: "20dp"
size_hint: (0.75, None) size_hint: (None, None)
width: '400sp'
# size:('400sp','800sp')
# adaptive_height: True
pos_hint: {"center_x": .5, "center_y": .5} pos_hint: {"center_x": .5, "center_y": .5}
md_bg_color: rgb(*COLOR_CARD) md_bg_color: rgb(*COLOR_CARD)
height: self.minimum_height height: self.minimum_height

@ -80,9 +80,9 @@ class PostCard(MDCard):
# pieces # pieces
author_section_layout = PostAuthorLayout() author_section_layout = PostAuthorLayout()
author_label = PostAuthorLabel(text='[b]'+self.author+'[/b]') author_label = PostAuthorLabel(text='@'+self.author)
author_label.font_size = '28dp' author_label.font_size = '18sp'
author_avatar = PostAuthorAvatar(source='avatar.jpg') #self.img_src) author_avatar = PostAuthorAvatar(source='assets/avatar.jpg') #self.img_src)
author_section_layout.add_widget(author_avatar) author_section_layout.add_widget(author_avatar)
author_section_layout.add_widget(author_label) author_section_layout.add_widget(author_label)
@ -100,9 +100,9 @@ class PostCard(MDCard):
if self.cache_img_src: if self.cache_img_src:
image_layout = PostImageLayout() image_layout = PostImageLayout()
self.image = image = PostImage(source=self.cache_img_src) self.image = image = PostImage(source=self.cache_img_src)
image.height = '300dp' image.height = '300sp'
image_layout.add_widget(image) image_layout.add_widget(image)
image_layout.height='300dp' image_layout.height='300sp'
# self.log(image.image_ratio) # self.log(image.image_ratio)
self.post_content = PostContent(text=self.content) self.post_content = PostContent(text=self.content)
@ -131,10 +131,10 @@ class PostCard(MDCard):
if height<minlen: height=minlen if height<minlen: height=minlen
return height return height
scroller.size = ('300dp','%sdp' % estimate_height()) scroller.size = ('300sp','%ssp' % estimate_height())
# scroller.bind(size=('300dp',scroller.setter('height')) # scroller.bind(size=('300sp',scroller.setter('height'))
scroller.add_widget(self.post_content) scroller.add_widget(self.post_content)
self.add_widget(scroller) self.add_widget(scroller)
# self.add_widget(post_layout) # self.add_widget(post_layout)

@ -126,7 +126,7 @@
text_color: rgb(*COLOR_TEXT) text_color: rgb(*COLOR_TEXT)
md_bg_color: 0,0,0,1 md_bg_color: 0,0,0,1
size_hint:None,None size_hint:None,None
font_size:'24sp' # font_size:'24sp'
# pos_hint: {'center_x': .5, 'bottom':1} # pos_hint: {'center_x': .5, 'bottom':1}
<RegisterButton>: <RegisterButton>:
@ -136,7 +136,7 @@
theme_text_color: "Custom" theme_text_color: "Custom"
text_color: rgb(*COLOR_TEXT) text_color: rgb(*COLOR_TEXT)
md_bg_color: 0,0,0,1 md_bg_color: 0,0,0,1
font_size:'24sp' # font_size:'24sp'
# size_hint:1,None # size_hint:1,None
<LoginStatus>: <LoginStatus>:

@ -90,8 +90,8 @@ class LoginScreen(BaseScreen):
self.label_title.font_size='22sp' self.label_title.font_size='22sp'
self.label_password.font_size='18sp' self.label_password.font_size='18sp'
self.label_username.font_size='18sp' self.label_username.font_size='18sp'
self.login_button.font_size='18sp' self.login_button.font_size='12sp'
self.register_button.font_size='18sp' self.register_button.font_size='12sp'

@ -72,7 +72,7 @@ class PostScreen(ProtectedScreen):
post_TextField.font_name='assets/overpass-mono-regular.otf' post_TextField.font_name='assets/overpass-mono-regular.otf'
post_TextField.hint_text='word?' post_TextField.hint_text='word?'
# post.remove_widget(post.scroller) post.remove_widget(post.scroller)
post.scroller.remove_widget(post.post_content) post.scroller.remove_widget(post.post_content)
post.scroller.add_widget(post_TextField) post.scroller.add_widget(post_TextField)
post.scroller.size=('300dp','300dp') post.scroller.size=('300dp','300dp')

@ -316,6 +316,8 @@ class ProfileScreen(BaseScreen):
# add posts # add posts
lim=25 lim=25
posts=await self.app.get_my_posts() posts=await self.app.get_my_posts()
# self.log('POSTS!?',posts)
# stop
for i,post in enumerate(posts): for i,post in enumerate(posts):
if i>lim: break if i>lim: break

@ -12,6 +12,7 @@ sys.path.append('../p2p')
BSEP=b'\n\n' BSEP=b'\n\n'
BSEP2=b'\t\n' BSEP2=b'\t\n'
BSEP3=b'\r\r' BSEP3=b'\r\r'
NODE_SLEEP_FOR=5
try: try:
from .crypto import * from .crypto import *
@ -96,7 +97,7 @@ class Api(object):
# self.root.ids.btn1.trigger_action() # self.root.ids.btn1.trigger_action()
i += 1 i += 1
await asyncio.sleep(1) await asyncio.sleep(NODE_SLEEP_FOR)
# pass # pass
except (asyncio.CancelledError,KeyboardInterrupt) as e: except (asyncio.CancelledError,KeyboardInterrupt) as e:
self.log('P2P node cancelled', e) self.log('P2P node cancelled', e)
@ -605,13 +606,12 @@ class Api(object):
async def get_json_val(self,uri,get_last=True): async def get_json_val(self,uri,get_last=True):
res=await self.get_json(uri,get_last=get_last) res=await self.get_json(uri,get_last=get_last)
self.log('get_json_val() got',res)
r=None r=None
if type(res) == dict: if type(res) == dict:
r=res.get('val',None) if res is not None else None r=res.get('val',None) if res is not None else None
elif type(res) == list: elif type(res) == list:
r=[x.get('val',None) for x in res if x is not None] r=[x.get('val',None) for x in res if x is not None]
self.log('get_json_val() giving back',r) self.log(f'get_json_val() --> {r}')
return r return r
async def get_post(self,post_id): async def get_post(self,post_id):
@ -619,7 +619,10 @@ class Api(object):
async def get_posts(self,uri='/posts/channel/earth'): async def get_posts(self,uri='/posts/channel/earth'):
# index = await self.get_json_val('/posts'+uri) # index = await self.get_json_val('/posts'+uri)
self.log(f'api.get_posts(uri={uri}) --> ...')
index = await self.get_json_val(uri,get_last=False) index = await self.get_json_val(uri,get_last=False)
if index is None: return [] if index is None: return []
if type(index)!=list: index=[index] if type(index)!=list: index=[index]
self.log('got index?',index) self.log('got index?',index)

@ -1,11 +1,15 @@
""" """
Package for interacting on the network at a high level. Package for interacting on the network at a high level.
""" """
STORE_ANYWHERE=True
import random import random
import pickle import pickle
import asyncio import asyncio
import logging import logging
from kademlia.protocol import KademliaProtocol from kademlia.protocol import KademliaProtocol
from kademlia.utils import digest from kademlia.utils import digest
from kademlia.storage import HalfForgetfulStorage from kademlia.storage import HalfForgetfulStorage
@ -153,7 +157,7 @@ class Server:
result = await self.protocol.ping(addr, self.node.id) result = await self.protocol.ping(addr, self.node.id)
return Node(result[1], addr[0], addr[1]) if result[0] else None return Node(result[1], addr[0], addr[1]) if result[0] else None
async def get(self, key): async def get(self, key, store_anywhere=STORE_ANYWHERE):
""" """
Get a key if the network has it. Get a key if the network has it.
@ -175,7 +179,8 @@ class Server:
found = await spider.find() found = await spider.find()
# set it locally? @EDIT # set it locally? @EDIT
self.storage.set(dkey,found) if store_anywhere:
self.storage.set(dkey,found)
return found return found
@ -195,7 +200,7 @@ class Server:
#dkey = digest(key) #dkey = digest(key)
return await self.set_digest(key, value) return await self.set_digest(key, value)
async def set_digest(self, key, value): async def set_digest(self, key, value, store_anywhere=STORE_ANYWHERE):
""" """
Set the given SHA1 digest key (bytes) to the given value in the Set the given SHA1 digest key (bytes) to the given value in the
network. network.
@ -216,12 +221,17 @@ class Server:
log.info("setting '%s' on %s", dkey.hex(), list(map(str, nodes))) log.info("setting '%s' on %s", dkey.hex(), list(map(str, nodes)))
# if this node is close too, then store here as well # if this node is close too, then store here as well
biggest = max([n.distance_to(node) for n in nodes]) if store_anywhere:
if self.node.distance_to(node) < biggest:
#self.storage[dkey] = value
## IMPOSSIBLE STORING UNDIGESTED IN LOCAL STORAGE FOR NOW @DEBUG @HACK
#self.storage.data_debug[key]=value
self.storage.set(dkey,value,undigested_too=key) self.storage.set(dkey,value,undigested_too=key)
else:
biggest = max([n.distance_to(node) for n in nodes])
if self.node.distance_to(node) < biggest:
#self.storage[dkey] = value
## IMPOSSIBLE STORING UNDIGESTED IN LOCAL STORAGE FOR NOW @DEBUG @HACK
#self.storage.data_debug[key]=value
self.storage.set(dkey,value,undigested_too=key)
results = [self.protocol.call_store(n, dkey, value) for n in nodes] results = [self.protocol.call_store(n, dkey, value) for n in nodes]
# return true only if at least one store call succeeded # return true only if at least one store call succeeded
return any(await asyncio.gather(*results)) return any(await asyncio.gather(*results))

Loading…
Cancel
Save