/*
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)
*/


#include "cPeer.h"
#include "misc.h"

extern uint8_t  this_hash[16];
cPeer::~cPeer() {{{
	if (name != NULL) free(name);
	}}}
cPeer::cPeer () {{{
	bzero (hash.hash, 16);
	set_Name("");
	set_Hash(hash.hash);
	expires = 0;
	madeContact = false;
	name = STRDUP ("");
	}}}
cPeer::cPeer (const uint8_t *KEY, uint32_t IP, uint16_t UDP, uint8_t TYPE) {{{
	set_Hash(KEY);
	ip   = IP;
	udp  = UDP;
	type = TYPE;
	expires = 0;
	madeContact = false;
	name = STRDUP ("");
	}}}
cPeer::cPeer (const uint8_t *KEY, uint32_t IP, uint16_t UDP, uint8_t TYPE, const char *NAME, uint16_t TCP) {{{
	set_Hash(KEY );
	name = STRDUP (NAME);
	ip   = IP;
	udp  = UDP;
	tcp  = TCP;
	type = TYPE;
	expires = 0;
	madeContact = false;
	}}}
void cPeer::set_Hash (const uint8_t *KEY ) {{{
	memcpy (hash.hash, KEY, 16);
	memcpy (dist.hash, KEY, 16);
	xor_128(dist.hash, this_hash);
	}}}
void cPeer::set_Name (const char    *NAME) {{{
	if (name != NULL) free(name);
	name = NULL;
	if (NAME != NULL) name = STRDUP (NAME);
	}}}

