Пример #1
0
def get_all_feed_events():
    path = str(Python.getPlatform().getApplication().getFilesDir())
    #public_key = ect.EventCreationTool.get_stored_feed_ids(directory_path=path, as_strings=False, relative=False)[0]

    db = kotlin.KotlinFunction()
    query_output = db.get_all_kotlin_events()
    pretty_output = []
    for tuple in query_output:
        type = tuple[0]
        if type == "post":
            timestamp = tuple[2]
            text = tuple[1]
            t = (type, get_uname_by_key(db, tuple[3]), timestamp, text)
        elif type == "username":
            new = tuple[1]
            old = tuple[2]
            timestamp = tuple[3]
            t = (type, new, old, timestamp)

        pretty_output.append(t)

    #print("query output")
    #print(query_output)
    #print("printing output")
    #print(pretty_output)
    return pretty_output
Пример #2
0
def get_all_usernames():
    db = kotlin.KotlinFunction()
    list = []
    #print(db.get_usernames_and_feed_id())
    for tuple in db.get_usernames_and_feed_id():
        name, key = tuple
        list.append(name)
    return list
Пример #3
0
def change_uname(new_uname):
    path = str(Python.getPlatform().getApplication().getFilesDir())
    db = kotlin.KotlinFunction()
    eg = ect.EventFactory(last_event=db.get_last_kotlin_event(), path_to_keys= path, path_to_keys_relative= False)
    timestamp = strftime("%Y-%m-%d %H:%M", gmtime())
    uname_event = eg.next_event("KotlinUI/username", {"newUsername": new_uname, "oldUsername": get_uname_by_key(db, get_pk()), "timestamp": timestamp})
    db.insert_data(uname_event)
    set_master_uname(new_uname)
Пример #4
0
def gui_get_pk():
    db = kotlin.KotlinFunction()
    path = str(Python.getPlatform().getApplication().getFilesDir())
    #print("printing both keys in get_pk()")
    public_key = ect.EventCreationTool.get_stored_feed_ids(directory_path=path, as_strings=False, relative=False)
    #print(public_key)
    if str(public_key[0]) == str(db.get_host_master_id()):
        return public_key[1].hex()
    return public_key[0].hex()
Пример #5
0
def get_my_feed_events():
    path = str(Python.getPlatform().getApplication().getFilesDir())
    public_key = get_pk()

    db = kotlin.KotlinFunction()

    #print("printing master id")
    #print(db.get_host_master_id().hex())
    #print("----------------------------------------------------------------")
    #print("printing public key")
    #print(public_key.hex())
    #print("----------------------------------------------------------------")

    query_output = db.get_all_entries_by_feed_id(public_key)
    pretty_output = []
    uname = get_uname_by_key(db, public_key)
    for tuple in query_output:
        type = tuple[0]
        if type == "post":
            timestamp = tuple[2]
            text = tuple[1]
            t = (type, uname, timestamp, text)
        elif type == "username":
            new = tuple[1]
            old = tuple[2]
            timestamp = tuple[3]
            t = (type, new, old, timestamp)

        pretty_output.append(t)

    #print('printing last kotlin event-------------------')
    #event = Event.Event.from_cbor(db.get_last_kotlin_event())
    #print("printing all kotlin events")
    #print(db.get_all_kotlin_events())
    #print("finished printing kotlin events")
    #print(event.meta.seq_no)
    #print('------------------------------------------------------------------------')
    #print("query output")
    #print(query_output)
    #print("printing output")
    #print(pretty_output)
    return pretty_output
Пример #6
0
def get_uname():
    path = str(Python.getPlatform().getApplication().getFilesDir())
    public_key = ect.EventCreationTool.get_stored_feed_ids(directory_path=path,
                                                           as_strings=False,
                                                           relative=False)
    if not public_key:
        return "NOT FOUND - PUBLIC KEY ARRAY EMPTY"
    else:
        public_key = public_key[0]

    db = kotlin.KotlinFunction()

    list = db.get_usernames_and_feed_id()
    print(len(list))
    for tuple in list:
        #print("comparing {} to {}".format(str(tuple[1]), str(public_key)))
        #print(str(tuple[1]))
        if str(tuple[1]) == str(public_key):
            uname = str(tuple[0])
            return uname
    return "NOT FOUND - USER NOT IN DB"
Пример #7
0
def insert_cbor(type, text):
    path = str(Python.getPlatform().getApplication().getFilesDir())
    db = kotlin.KotlinFunction()
    db.get_host_master_id()
    timestamp = strftime("%Y-%m-%d %H:%M", gmtime())
    public_keys = ect.EventCreationTool.get_stored_feed_ids(directory_path=path, as_strings=False, relative=False)

    #if True:
    if not public_keys:
        eg = ect.EventFactory(path_to_keys=path, path_to_keys_relative=False)
        # VERY first event (for feedCTRL)
        first_event = eg.first_event('KotlinUI', db.get_host_master_id())
        db.insert_data(first_event)
        # first event (INSERTED BY user) where the user get assigned the name Anonymous
        first_event_byApp = eg.next_event('KotlinUI/username', {"newUsername": "******", "oldUsername": "", "timestamp": timestamp})
        set_master_uname("Anonymous")
        db.insert_data(first_event_byApp)

        # re-compute public_keys, now it should contain exactly one element
        public_keys = ect.EventCreationTool.get_stored_feed_ids(directory_path=path, as_strings=False, relative=False)

    public_key = str(public_keys[0])
    list = db.get_usernames_and_feed_id()

    uname = get_uname_by_key(db, public_key)

    # this should NEVER EVER be true, EVER
    if uname == "NOT FOUND":
        uname = "Anonymous"

    eg = ect.EventFactory(last_event=db.get_last_kotlin_event(), path_to_keys= path, path_to_keys_relative= False)
    if type == "username":
        new_event = eg.next_event("KotlinUI/username", {"newUsername": uname, "oldUsername": "******", "timestamp": timestamp})
        set_master_uname(uname)
    else:
        new_event = eg.next_event("KotlinUI/post", {"username": uname, "timestamp": timestamp, "text": text})
    db.insert_data(new_event)
Пример #8
0
def start():
    feedCTRL.cli('')
    #print("feed control control")
    #return
    path = str(Python.getPlatform().getApplication().getFilesDir())
    db = kotlin.KotlinFunction()
    db.get_host_master_id()
    timestamp = strftime("%Y-%m-%d %H:%M", gmtime())
    public_keys = ect.EventCreationTool.get_stored_feed_ids(directory_path=path, as_strings=False, relative=False)

    if len(public_keys) <= 1:
        eg = ect.EventFactory(path_to_keys=path, path_to_keys_relative=False)

        # VERY first event (for feedCTRL)
        #first_event = eg.next_event('KotlinUI/MASTER', {'master_feed': eg.get_feed_id()})
        first_event = eg.first_event('KotlinUI', db.get_host_master_id())
        #first_event = eg.first_event('KotlinUI', eg.get_feed_id())
        #first_event = eg.next_event('KotlinUI', eg.get_feed_id())

        db.insert_data(first_event)
        first_event_byApp = eg.next_event('KotlinUI/username', {"newUsername": "******", "oldUsername": "", "timestamp": timestamp})
        db.insert_data(first_event_byApp)
        set_master_uname("Anonymous")

    #feedCTRL.cli('-t 0 0')
    #feedCTRL.cli('-t 0 1')
    #feedCTRL.cli('-t 1 0')
    #feedCTRL.cli('-t 1 1')

    #print("printing the len of public keys")
    #print(len(public_keys))
    #print("finished printing len of public keys")
    #print("This should contain AT LEAST 2 events")
    #print(db.get_all_kotlin_events())
    #print("-----------------------")
    print('TESTING CLI FUNCTION')
Пример #9
0
def get_uname():
    db = kotlin.KotlinFunction()
    pk = get_pk()
    return get_uname_by_key(db, pk)