peerexchange.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * peerexchange.h
  3. * Niagara
  4. *
  5. * Created by Ryan Walklin on 24/05/07.
  6. * Copyright 2007 Ryan Walklin. All rights reserved.
  7. *
  8. * Released under the GNU GENERAL PUBLIC LICENCE.
  9. *
  10. */
  11. #include <netinet/in.h>
  12. #include "types.h"
  13. // Message defines
  14. #define BT_MSG_EXTENDED 20
  15. #define BT_EXT_HANDSHAKE 0
  16. #define BT_EXT_UTPEX 1
  17. // Def to 1 for debug stderr output
  18. #define PEX_DEBUG 1
  19. enum {
  20. TRACKER = 0,
  21. CACHE,
  22. PEX
  23. };
  24. typedef struct btPeerAddress {
  25. struct in_addr ip; // ip address in network order
  26. uint16_t port;
  27. } btPeerAddress;
  28. typedef struct btPeerCache {
  29. int len;
  30. struct btPeerAddress **address;
  31. int allocated;
  32. } btPeerCache;
  33. struct btDownload;
  34. struct btPeer;
  35. // Peer Exchange
  36. int sendExtendedHandshake(struct btPeer *peer, int listenPort,
  37. int privateflag);
  38. int buildDictFromCurrentPeersForPeer(btDict * targetDict,
  39. struct btPeer *peer);
  40. int sendPeerExchange(struct btDownload *dl, struct btPeer *peer);
  41. // Peer Cache
  42. btPeerCache *btPeerCache_Create(btPeerCache * cache);
  43. int btPeerCache_AddPeer(btPeerCache * cache, struct btPeer *peer);
  44. int btPeerCache_GetPosition(btPeerCache * cache, struct btPeer *peer);
  45. int btPeerCache_DelPeer(btPeerCache * cache, int position);
  46. void btPeerCache_Destroy(btPeerCache * cache);