/*
 * 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 _BOOTSTRAP_H
#define _BOOTSTRAP_H

#include "node.h"

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

#ifdef _WENGO
#include "p2pp/common/types.h"
#include "p2pp/msg/msgheader.h"
#include "p2pp/bigint/bigint.h"
#endif

#include <list>
using namespace std;

class Bootstrap : public Node {

private:
  struct peerinfo m_stPeer;
  uint32 m_uiTransId;

private:
  void ComposeBootstrapResp();  
  int32 getSelfPeer(struct peerinfo& stP);
  int32 compareAddr(const struct peerinfo& stFirst, const struct peerinfo& stSecond);
  int32 removeSimilar(const struct peerinfo& stPeer);

  char8 m_ID[255];
  list<peerinfo> m_BSP;

public:
  Bootstrap();
  virtual ~Bootstrap();

  virtual void Initialize();
  void OnTimer();
  int32 OnReceive(uchar* buf, int len, char* pchIP, int32 port, transtype tt);

  int32 PublishObject (char8* pchKey, int32 klen, char8* pchValue, int32 vlen, void* (*)(void*, int32), void* pApp);
  int32 LookupObject (char8* pchKey, int32 klen, void* (*)(void*, int32), void* pApp );
  int32 LookupPeer (char8* pchKey, int32 klen, void* (*)(void*, int32), void* pApp );

  void ComposeDiagnosticsResp(char* pchIP, int32 port, transtype tt);
};

#endif

