/*
This Work is under GPL provided with this work.

This work is based on the java implementation of the Kademlia protocol.
Kademlia: Peer-to-peer routing based on the XOR metric
Copyright (C) 2002  Petar Maymounkov [petar@post.harvard.edu]
http://kademlia.scs.cs.nyu.edu
and
This work is bassed on translation from Barry Dunne to C++
Copyright (C)2003 Barry Dunne (http://www.emule-project.net)
*/


#ifndef cBucket_h
#define cBucket_h
#include <list>
#include <map>
#include "cygwin.h"

typedef std::list<class cPeer*> cPeerList;
typedef std::map<class cHash, class cPeer*> cPeerMap;
class cBucket {
private:
	cPeerList	 contacts;
public:	
	bool 		 dontDeleteContacts;
			~cBucket	();
			 cBucket	() { dontDeleteContacts = false; }
	bool		 add		(class cPeer *PEER);
	void		 setAlive	(uint32_t IP, uint16_t PORT);
	void		 remove		(class cPeer *PEER) { contacts.remove(PEER); }
	bool		 contains	(const uint8_t *KEY) { return (getContact(KEY) != NULL); }
	class cPeer*	 getContact	(const uint8_t *KEY);
	class cPeer*	 getOldest	(void);
	size_t		 getSize	(void) const { return      contacts.size();}
	size_t		 getRemaining	(void) const { return 20 - contacts.size(); }
	void		 getContacts	(cPeerList *CONTACTS, bool EMPTY = true);
	size_t		 getClosest	(const uint8_t *KEY, size_t max, cPeerMap *MAP, bool EMPTY);

	void		 dumpContents	(void);
	};

#endif
