Skip to content

Add bitswap commands #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ipfsApi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Client(object):
block_stat -- returns a dict with the size of the block with the given hash
block_get -- returns the raw contents of a block
block_put -- stores input as an IPFS block
bitswap_wantlist -- show blocks currently on the wantlist
bitswap_stat -- show some diagnostic information on the bitswap agent
bitswap_unwant -- remove a given block from wantlist
object_data -- returns the raw bytes in an IPFS object
object_new -- creates a new object from an ipfs template
object_links -- returns the links pointed to by the specified object
Expand Down Expand Up @@ -121,6 +124,10 @@ def __init__(self, host=None, port=None,
self._block_get = ArgCommand('/block/get')
self._block_put = FileCommand('/block/put')
self._object_new = ArgCommand('/object/new')
self._bitswap_wantlist = ArgCommand('/bitswap/wantlist')
self._bitswap_stat = Command('/bitswap/stat')
self._bitswap_unwant = ArgCommand('/bitswap/unwant')

self._object_data = ArgCommand('/object/data')
self._object_links = ArgCommand('/object/links')
self._object_get = ArgCommand('/object/get')
Expand Down Expand Up @@ -318,6 +325,30 @@ def block_put(self, file, **kwargs):
"""
return self._block_put.request(self._client, (), file, **kwargs)

def bitswap_wantlist(self, peer=None, **kwargs):
"""
Show blocks currently on the wantlist.

:param peer: Peer to show wantlist for.
"""
return self._bitswap_wantlist.request(self._client, peer, **kwargs)

def bitswap_stat(self, **kwargs):
"""
Show some diagnostic information on the bitswap agent.
"""

return self._bitswap_stat.request(self._client, **kwargs)

def bitswap_unwant(self, key, **kwargs):
"""
Remove a given block from wantlist.

:param key: Key to remove from wantlist.
"""

return self._bitswap_unwant.request(self._client, key, **kwargs)

def object_data(self, multihash, **kwargs):
r"""Returns the raw bytes in an IPFS object.

Expand Down
23 changes: 23 additions & 0 deletions test/functional/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,5 +492,28 @@ def test_object_patch_set_data(self):
self.assertEqual(result,
{'Hash': 'QmV4QR7MCBj5VTi6ddHmXPyjWGzbaKEtX2mx7axA5PA13G'})

@skipIfOffline()
class IpfsApiBitswapTest(unittest.TestCase):

def setUp(self):
self.api = ipfsApi.Client()

def test_bitswap_wantlist(self):
result = self.api.bitswap_wantlist(peer='QmdkJZUWnVkEc6yfptVu4LWY8nHkEnGwsxqQ233QSGj8UP')
self.assertTrue(result and type(result) is dict and 'Keys' in result)

def test_bitswap_stat(self):
result = self.api.bitswap_stat()
self.assertTrue(result and type(result) is dict and 'Wantlist' in result)

def test_bitswap_unwant(self):
"""
Cannot ensure what is present in the wantlist prior to execution, so just ensure
something comes back.
"""

result = self.api.bitswap_unwant(key='QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V')
self.assertTrue(result is not None)

if __name__ == "__main__":
unittest.main()