예제 #1
0
def download_blocks(peer, peers_block_count, length):
    b = [
        max(0, length - 10),
        min(peers_block_count['length'] + 1, length + custom.download_many)
    ]

    # tell them our request's range
    blocks = network_cmd(peer, {'type': 'rangeRequest', 'range': b})

    if type(blocks) != list: return -1

    if not isinstance(blocks, list): return []

    length = tools.db_get('length')  # our blockcount
    block = tools.db_get(length)  # get the last block

    for i in range(
            10
    ):  # this part should be re-written so badly -> this was from Zack.... NO COMMENT
        if tools.fork_check(blocks, custom.queues, length,
                            block):  # if block is valid
            blockchain.delete_block(custom.queues)  # wtf does this do?
            length -= 1

    for block in blocks:
        custom.queues['suggested_blocks'].put([block, peer])

    return 0
예제 #2
0
def pushblock(dic, DB):
    if 'blocks' in dic:
        for i in range(20):
            if tools.fork_check(dic['blocks'], DB):
                blockchain.delete_block(DB)
        for block in dic['blocks']:
            DB['suggested_blocks'].put([block, dic['peer']])
    else:
        DB['suggested_blocks'].put([dic['block'], dic['peer']])
    return 'success'
예제 #3
0
def pushblock(dic, DB):
    if 'blocks' in dic:
        for i in range(20):
            if tools.fork_check(dic['blocks'], DB):
                blockchain.delete_block(DB)
        for block in dic['blocks']:
            DB['suggested_blocks'].put([block, dic['peer']])
    else:
        DB['suggested_blocks'].put([dic['block'], dic['peer']])
    return 'success'
예제 #4
0
def download_blocks(peer, DB, peers_block_count, length):
    b=[max(0, length-10), min(peers_block_count, length+custom.download_many)]
    blocks = cmd(peer, {'type': 'rangeRequest', 'range': b})
    if type(blocks)!=list: return -1
    if not isinstance(blocks, list): return []
    length=tools.db_get('length')
    block=tools.db_get(length)
    for i in range(10):#this part should be re-written so badly
        if tools.fork_check(blocks, DB, length, block):
            blockchain.delete_block(DB)
            length-=1
    for block in blocks:
        DB['suggested_blocks'].put([block, peer])
    return 0
예제 #5
0
def pushblock(dic, DB):
    length=tools.db_get('length')
    block = tools.db_get(length, DB)    
    if 'peer' in dic: peer=dic['peer']
    else: peer=False
    if 'blocks' in dic:
        for i in range(20):
            if tools.fork_check(dic['blocks'], DB, length, block):
                blockchain.delete_block(DB)
                length-=1
        for block in dic['blocks']:
            DB['suggested_blocks'].put([block, peer])
    else:
        DB['suggested_blocks'].put([dic['block'], peer])
    return 'success'
예제 #6
0
def pushblock(dic, DB):
    length = tools.db_get('length')
    block = tools.db_get(length, DB)
    if 'peer' in dic: peer = dic['peer']
    else: peer = False
    if 'blocks' in dic:
        for i in range(20):
            if tools.fork_check(dic['blocks'], DB, length, block):
                blockchain.delete_block(DB)
                length -= 1
        for block in dic['blocks']:
            DB['suggested_blocks'].put([block, peer])
    else:
        DB['suggested_blocks'].put([dic['block'], peer])
    return 'success'
예제 #7
0
def download_blocks(peer, DB, peers_block_count, length):
    b = [
        max(0, length - 10),
        min(peers_block_count, length + custom.download_many)
    ]
    blocks = cmd(peer, {'type': 'rangeRequest', 'range': b})
    if type(blocks) != list: return -1
    if not isinstance(blocks, list): return []
    length = tools.db_get('length')
    block = tools.db_get(length)
    for i in range(10):  #this part should be re-written so badly
        if tools.fork_check(blocks, DB, length, block):
            blockchain.delete_block(DB)
            length -= 1
    for block in blocks:
        DB['suggested_blocks'].put([block, peer])
    return 0
예제 #8
0
def download_blocks(peer, DB, peers_block_count, length):
    b=[max(0, length-10), min(peers_block_count['length'], length+custom.download_many)]
    #tools.log('asked for: ' +str(b))
    blocks = cmd(peer, {'type': 'rangeRequest',
                        'range': b})
    if type(blocks)!=list:
        #tools.log('unable to download blocks that time')
        return -1
    if not isinstance(blocks, list):
        return []
    for i in range(20):  # Only delete a max of 20 blocks, otherwise a
        # peer might trick us into deleting everything over and over.
        if tools.fork_check(blocks, DB):
            blockchain.delete_block(DB)
    for block in blocks:
        DB['suggested_blocks'].put([block, peer])
    return 0
예제 #9
0
def download_blocks(peer, DB, peers_block_count, length):
    b = [
        max(0, length - 10),
        min(peers_block_count['length'], length + custom.download_many)
    ]
    #tools.log('asked for: ' +str(b))
    blocks = cmd(peer, {'type': 'rangeRequest', 'range': b})
    if type(blocks) != list:
        #tools.log('unable to download blocks that time')
        return -1
    if not isinstance(blocks, list):
        return []
    for i in range(20):  # Only delete a max of 20 blocks, otherwise a
        # peer might trick us into deleting everything over and over.
        if tools.fork_check(blocks, DB):
            blockchain.delete_block(DB)
    for block in blocks:
        DB['suggested_blocks'].put([block, peer])
    return 0
예제 #10
0
def download_blocks(peer, peers_block_count, length):
    b = [max(0, length - 10), min(peers_block_count['length'] + 1, length + custom.download_many)]

    # tell them our request's range
    blocks = network_cmd(peer, {'type': 'rangeRequest', 'range': b})

    if type(blocks) != list: return -1

    if not isinstance(blocks, list): return []

    length = tools.db_get('length')  # our blockcount
    block = tools.db_get(length)  # get the last block

    for i in range(10):  # this part should be re-written so badly -> this was from Zack.... NO COMMENT
        if tools.fork_check(blocks, custom.queues, length, block):  # if block is valid
            blockchain.delete_block(custom.queues)  # wtf does this do?
            length -= 1

    for block in blocks:
        custom.queues['suggested_blocks'].put([block, peer])

    return 0