コード例 #1
0
ファイル: basic.py プロジェクト: zidz/bithorde
#!/usr/bin/env python

from bithordetest import message, BithordeD, Cache, TestConnection, TigerId

if __name__ == '__main__':
    ASSET = "A" * 87234
    ASSET_TTH = "5V7AM5PT6PVGTCWITETZUFPBTCDK2DPHBJMTFWI"

    bithorded = BithordeD(config={
        'cache': {'dir': Cache() },
        'client.tester.addr': '',
    })
    conn = TestConnection(bithorded, name='tester')

    # Open an invalid handle
    conn.send(message.BindRead(handle=1, ids=[TigerId("IDONOTEXISTO")], timeout=500))
    conn.expect(message.AssetStatus(handle=1, status=message.NOTFOUND))

    # Create small asset
    conn.send(message.BindWrite(handle=1, size=len(ASSET)))
    conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS))

    conn.send(message.DataSegment(handle=1, offset=0, content=ASSET))
    conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS, ids=[TigerId(ASSET_TTH)]))

    conn.send(message.BindRead(handle=1, ids=[TigerId(ASSET_TTH)], timeout=500))
    conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS, size=len(ASSET), ids=[TigerId(ASSET_TTH)]))

    conn.send(message.Read.Request(reqId=1, handle=1, offset=0, size=len(ASSET), timeout=500))
    conn.expect(message.Read.Response(reqId=1, status=message.SUCCESS, offset=0, content=ASSET[:65536]))
コード例 #2
0
from bithordetest import message, BithordeD, Cache, TestConnection, TigerId

if __name__ == '__main__':
    ASSET = "A" * 87234
    ASSET_TTH = "5V7AM5PT6PVGTCWITETZUFPBTCDK2DPHBJMTFWI"

    bithorded = BithordeD(config={
        'cache': {
            'dir': Cache()
        },
        'client.tester.addr': '',
    })
    conn = TestConnection(bithorded, name='tester')

    # Open an invalid handle
    conn.send(
        message.BindRead(handle=1, ids=[TigerId("IDONOTEXISTO")], timeout=500))
    conn.expect(message.AssetStatus(handle=1, status=message.NOTFOUND))

    # Create small asset
    conn.send(message.BindWrite(handle=1, size=len(ASSET)))
    conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS))

    conn.send(message.DataSegment(handle=1, offset=0, content=ASSET))
    conn.expect(
        message.AssetStatus(handle=1,
                            status=message.SUCCESS,
                            ids=[TigerId(ASSET_TTH)]))

    conn.send(message.BindRead(handle=1, ids=[TigerId(ASSET_TTH)],
                               timeout=500))
    conn.expect(
コード例 #3
0
ファイル: reconnect_asset.py プロジェクト: rawler/bithorde
#!/usr/bin/env python2

from bithordetest import message, BithordeD, TestConnection

if __name__ == '__main__':
    bithorded = BithordeD(config={
        'friend.evilservant.addr': '',
    })
    conn = TestConnection(bithorded, name='tester')
    server = TestConnection(bithorded, name='evilservant')

    # Open a valid handle
    conn.send(message.BindRead(handle=1, ids=[message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT')], timeout=500))
    assetReq = server.expect(message.BindRead)
    server.send(message.AssetStatus(handle=assetReq.handle, ids=assetReq.ids, status=message.SUCCESS, size=1024))
    conn.expect(message.AssetStatus(handle=1, ids=assetReq.ids, status=message.SUCCESS))

    # Send a pending read-request.
    conn.send(message.Read.Request(reqId=1, handle=1, offset=0, size=1024, timeout=500))
    server.expect(message.Read.Request(handle=assetReq.handle, offset=0, size=1024))

    # Close upstream server
    server.close()
    bithorded.wait_for("Disconnected: evilservant")
    conn.expect([
        message.Read.Response(reqId=1, status=message.NOTFOUND, offset=0),
        message.AssetStatus(handle=1, status=message.NOTFOUND),
    ])

    # Reconnect upstream server
    server = TestConnection(bithorded, name='evilservant')
コード例 #4
0
ファイル: test_random_reads.py プロジェクト: rawler/bithorde
        pass
    bithorded = BithordeD(config={
        'friend.server.addr': '',
        'cache': {
            'dir': 'cache',
            'size': 8192,
        },
    })
    server = TestConnection(bithorded, name='server')
    client = TestConnection(bithorded, name='client')

    dummy_ids = [
        message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT')]

    # Send request, and wait for it to arrive at server and time out
    client.send(message.BindRead(handle=1, ids=dummy_ids, timeout=50))
    server_asset = server.expect(message.BindRead)
    server.send(message.AssetStatus(handle=server_asset.handle,
                                    ids=server_asset.ids, size=ASSET_SIZE, status=message.SUCCESS))
    client.expect(message.AssetStatus(handle=1, status=message.SUCCESS))

    # Delayed cache-creation works.
    assert len(os.listdir('cache/assets')) == 0

    import threading
    t = threading.Thread(target=responder, args=(server,))
    t.start()

    for i in xrange(64, 4096, 64):
        client.send(message.Read.Request(
            reqId=1, handle=1, offset=i * 4, size=i, timeout=2000))
コード例 #5
0
ファイル: loop_prevention.py プロジェクト: rawler/bithorde
ASSET_IDS = [message.Identifier(type=message.TREE_TIGER, id='GIS3CRGMSBT7CKRBLQFXFAL3K4YIO5P5E3AMC2A')]
INITIAL_REQUEST = randint(0,(2**64)-1)

if __name__ == '__main__':
    bithorded = BithordeD(config={
        'friend.upstream1.addr': '',
        'friend.upstream2.addr': '',
    })
    upstream1 = TestConnection(bithorded, name='upstream1')
    upstream2 = TestConnection(bithorded, name='upstream2')
    downstream1 = TestConnection(bithorded, name='downstream1')
    downstream2 = TestConnection(bithorded, name='downstream2')

    # Request an asset-session
    downstream1.send(message.BindRead(handle=1, ids=ASSET_IDS, timeout=500, requesters=[INITIAL_REQUEST]))
    req1 = upstream1.expect(message.BindRead)
    assert len(req1.requesters) > 1
    assert INITIAL_REQUEST in req1.requesters
    assert INITIAL_REQUEST == req1.requesters[-1] # Try to keep backwards compatibility
    server_id = next(x for x in req1.requesters if x != INITIAL_REQUEST)

    # Let upstream1 join as server
    upstream1.send(message.AssetStatus(handle=req1.handle, status=message.SUCCESS, ids=ASSET_IDS, servers=[99998888], size=15))
    resp = downstream1.expect(message.AssetStatus)
    assert len(resp.servers) > 1
    assert 99998888 in resp.servers
    assert server_id in resp.servers

    # Let upstream2 join as server
    req2 = upstream2.expect(message.BindRead)
コード例 #6
0
#!/usr/bin/env python2

from bithordetest import message, BithordeD, TestConnection

if __name__ == '__main__':
    bithorded = BithordeD(config={
        'friend.evilservant.addr': '',
    })
    conn = TestConnection(bithorded, name='tester')
    server = TestConnection(bithorded, name='evilservant')

    # Open a valid handle
    conn.send(
        message.BindRead(handle=1,
                         ids=[
                             message.Identifier(type=message.TREE_TIGER,
                                                id='NON-EXISTANT')
                         ],
                         timeout=500))
    assetReq = server.expect(message.BindRead)
    server.send(
        message.AssetStatus(handle=assetReq.handle,
                            ids=assetReq.ids,
                            status=message.SUCCESS,
                            size=1024))
    conn.expect(
        message.AssetStatus(handle=1, ids=assetReq.ids,
                            status=message.SUCCESS))

    # Send a pending read-request.
    conn.send(
コード例 #7
0
ファイル: asset_timeout.py プロジェクト: loffeloffe/bithorde
#!/usr/bin/env python2

from bithordetest import message, BithordeD, TestConnection

if __name__ == '__main__':
    bithorded = BithordeD(config={
        'friend.deadservant.addr': ''
    })
    server = TestConnection(bithorded, name='deadservant')
    conn = TestConnection(bithorded, name='tester')

    dummy_ids = [message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT')]

    # Send request, and wait for it to arrive at server and time out
    conn.send(message.BindRead(handle=1, ids=dummy_ids, timeout=50))
    req = server.expect(message.BindRead)
    bithorded.wait_for("Failed upstream deadservant")
    conn.expect(message.AssetStatus(handle=1, status=message.NOTFOUND))

    # BithordeD should now have closed the connection. Hold the confirmation.
    req = server.expect(message.BindRead(handle=req.handle, ids=[]))

    # Re-bind, now with responding source
    conn.send(message.BindRead(handle=1, ids=dummy_ids, timeout=5000))
    req2 = server.expect(message.BindRead(ids=dummy_ids))
    assert req.handle != req2.handle # Since we did not confirm the close before, bithorde should not yet have re-used the handle.
    server.send(message.AssetStatus(handle=req2.handle, ids=req2.ids, status=message.SUCCESS))
    conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS))

    # Now close both handles and confirm the closing
    server.send(message.AssetStatus(handle=req.handle, status=message.NOTFOUND))
コード例 #8
0
    bithorded = BithordeD(config={
        'friend.server.addr': '',
        'cache': {
            'dir': 'cache',
            'size': 8192,
        },
    })
    server = TestConnection(bithorded, name='server')
    client = TestConnection(bithorded, name='client')

    dummy_ids = [
        message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT')
    ]

    # Send request, and wait for it to arrive at server and time out
    client.send(message.BindRead(handle=1, ids=dummy_ids, timeout=50))
    server_asset = server.expect(message.BindRead)
    server.send(
        message.AssetStatus(handle=server_asset.handle,
                            ids=server_asset.ids,
                            size=ASSET_SIZE,
                            status=message.SUCCESS))
    client.expect(message.AssetStatus(handle=1, status=message.SUCCESS))

    # Delayed cache-creation works.
    assert len(os.listdir('cache/assets')) == 0

    import threading
    t = threading.Thread(target=responder, args=(server, ))
    t.start()
コード例 #9
0
INITIAL_REQUEST = randint(0, (2**64) - 1)

if __name__ == '__main__':
    bithorded = BithordeD(config={
        'friend.upstream1.addr': '',
        'friend.upstream2.addr': '',
    })
    upstream1 = TestConnection(bithorded, name='upstream1')
    upstream2 = TestConnection(bithorded, name='upstream2')
    downstream1 = TestConnection(bithorded, name='downstream1')
    downstream2 = TestConnection(bithorded, name='downstream2')

    # Request an asset-session
    downstream1.send(
        message.BindRead(handle=1,
                         ids=ASSET_IDS,
                         timeout=500,
                         requesters=[INITIAL_REQUEST]))
    req1 = upstream1.expect(message.BindRead)
    assert len(req1.requesters) > 1
    assert INITIAL_REQUEST in req1.requesters
    assert INITIAL_REQUEST == req1.requesters[
        -1]  # Try to keep backwards compatibility
    server_id = next(x for x in req1.requesters if x != INITIAL_REQUEST)

    # Let upstream1 join as server
    upstream1.send(
        message.AssetStatus(handle=req1.handle,
                            status=message.SUCCESS,
                            ids=ASSET_IDS,
                            servers=[99998888],