/*
 * Copyright (C) 2008 The Trustees of Columbia University in the City of New York. 
 * All rights reserved.
 *
 * See the file LICENSE included in this distribution for details.
 */

#ifndef _TABLE_H
#define _TABLE_H


#ifndef _WENGO
#include "types.h"
#include "bigint.h"
#include "msgheader.h"
#include "chorddist.h"
#include "gettimeofday.h"
#endif

#ifdef _WENGO
#include "p2pp/common/types.h"
#include "p2pp/bigint/bigint.h"
#include "p2pp/msg/msgheader.h"
#include "p2pp/distance/chorddist.h"
#include "p2pp/sys/gettimeofday.h"
#endif


struct Internalpeerinfo {
  struct peerinfo m_stP;
  struct timeval m_lastseen;
  //other members can be added later for things like security and optimization.
  
  struct timeval m_expKA;
  struct timeval m_expRT;
  
  struct timeval m_tLastSent;
  struct timeval m_tRTT;

  uint16 m_iStunPort;

  BigInt ID;
  
  Internalpeerinfo() {
    //Initialize RTT value
    m_tRTT.tv_sec = 0;
    m_tRTT.tv_usec = 0;
    m_iStunPort = 0;
  }
};


class Peer;

class Table
{
  
 protected:
  Peer* m_pPeer;

 public:
  Table();
  virtual ~Table();
  virtual uint32 getSize() = 0;
  
  virtual uint32 getNextHop(uchar* peerid, uint32 len, struct peerinfo& stP) = 0;
  virtual uint32 getNextHop(BigInt, peerinfo&) = 0;     //Sets
  //the peerinfo object to the peer which should be the next hop in the lookup for lkey.

  //Insert stP into the table.  
  virtual int32 Insert(const struct peerinfo& stP, int32 updateKA);
  virtual int32 Insert(const struct peerinfo& stP, int32 updateKA, uint16 stunPort);
  virtual int32 Insert(const list<peerinfo>& lstP, int32 updateKA);  

  virtual int32 getTable(list<peerinfo>& lstP){return 1;}  
  virtual int32 getTable(list<peerinfo>& lstP, enum transtype tt) {return 1;}

  virtual void Show() {};

  virtual int32 OnTimer();

  void setParams(Peer* pPeer);

  virtual void Disconnect();

};
#endif
