Now it compiles on Cygwin

This commit is contained in:
mpc
2004-06-22 22:48:32 +00:00
committed by zzz
parent 7ca35452eb
commit eb5dd2ff2e
11 changed files with 36 additions and 30 deletions

View File

@@ -154,12 +154,14 @@ bool Bigint::operator>(const Bigint& rhs) const
}
/*
* Xors another Bigint with this Bigint and puts the result in Bigint `result'
* Xors another Bigint with this Bigint and puts the result in Bigint `result'.
* We can't name it "xor" because that word is reserved in C++ (see Appendex C,
* section 3.1 in TC++PL).
*
* rhs - the bigint to xor with
* result - will be filled with the result of the xor
*/
void Bigint::xor(const Bigint& rhs, Bigint& result) const
void Bigint::x_or(const Bigint& rhs, Bigint& result) const
{
int rc = mp_xor(const_cast<mp_int*>(&mpi), const_cast<mp_int*>(&rhs.mpi),
&result.mpi);

View File

@@ -47,7 +47,7 @@ class Bigint {
Bigint& operator=(const Bigint& rhs);
bool operator==(const Bigint& rhs) const;
bool operator>(const Bigint& rhs) const;
void xor(const Bigint& rhs, Bigint& result) const;
void x_or(const Bigint& rhs, Bigint& result) const;
protected:
mp_int mpi;
@@ -57,4 +57,4 @@ class Bigint {
void init(void);
};
#endif // BIGINT_HPP
#endif // BIGINT_HPP

View File

@@ -39,17 +39,17 @@
* LERROR - major, important errors
*/
#if VERBOSE_LOGS
#define LDEBUG logger.set_pri(Logger::debug); logger << "(D)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << "(): "
#define LMINOR logger.set_pri(Logger::minor); logger << "(M)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << "(): "
#define LINFO logger.set_pri(Logger::info); logger << "(I)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << "(): "
#define LWARN logger.set_pri(Logger::warn); logger << "(W)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << "(): "
#define LERROR logger.set_pri(Logger::error); logger << "(E)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << "(): "
#define LDEBUG logger.set_pri(Logger::debug); logger << "(D)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << ": "
#define LMINOR logger.set_pri(Logger::minor); logger << "(M)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << ": "
#define LINFO logger.set_pri(Logger::info); logger << "(I)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << ": "
#define LWARN logger.set_pri(Logger::warn); logger << "(W)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << ": "
#define LERROR logger.set_pri(Logger::error); logger << "(E)" << __FILE__ << ':' << __LINE__ << ':' << __func__ << ": "
#else
#define LDEBUG logger.set_pri(Logger::debug); logger
#define LMINOR logger.set_pri(Logger::minor); logger
#define LINFO logger.set_pri(Logger::info); logger
#define LWARN logger.set_pri(Logger::warn); logger
#define LERROR logger.set_pri(Logger::error); logger
#define LDEBUG logger.set_pri(Logger::debug); logger << "(D)"
#define LMINOR logger.set_pri(Logger::minor); logger << "(M)"
#define LINFO logger.set_pri(Logger::info); logger << "(I)"
#define LWARN logger.set_pri(Logger::warn); logger << "(W)"
#define LERROR logger.set_pri(Logger::error); logger << "(E)"
#endif
class Logger {

View File

@@ -46,12 +46,16 @@ int main(int argc, char* argv[])
LINFO << "Enclave DHT - Built on " << __DATE__ << ' ' << __TIME__ << '\n';
try {
sam = new Sam("eldritch", 7656, argv[1], 0);
sam = new Sam("localhost", 7656, argv[1], 0);
} catch (const Sam_error& x) {
LERROR << "SAM error: " << x.what() << '\n';
if (x.code() == SAM_SOCKET_ERROR)
cerr << "SAM error: " << x.what() << '\n';
if (x.code() == SAM_SOCKET_ERROR) {
LERROR << "Check whether you have specified the correct SAM host " \
"and port number\n";
"and port number, and that\nI2P is running.\n";
cerr << "Check whether you have specified the correct SAM host " \
"and port number, and that\nI2P is running.\n";
}
return 1;
}
sam->naming_lookup();

View File

@@ -51,4 +51,4 @@ class Near_peer {
Peer* peer;
};
#endif // NEAR_PEER_HPP
#endif // NEAR_PEER_HPP

View File

@@ -42,7 +42,8 @@ void Peers::advertise_self(void)
{
list<Near_peer> near_peers;
get_nearest(sam->get_my_sha1(), PAR_RPCS, near_peers);
for (near_peers_ci i = near_peers.begin(); i != near_peers.end(); i++) {
for (list<Near_peer>::const_iterator i = near_peers.begin();
i != near_peers.end(); i++) {
Rpc rpc(i->get_peer());
rpc.find_peers(sam->get_my_sha1());
}
@@ -61,7 +62,7 @@ void Peers::get_nearest(const Sha1& sha1, size_t n, list<Near_peer>& near_peers)
for (peersmap_i i = peersmap.begin(); i != peersmap.end(); i++) {
const Sha1& kaddr = i->first;
Bigint distance;
sha1.xor(kaddr, distance);
sha1.x_or(kaddr, distance);
Near_peer np(distance, &(i->second));
near_peers.insert(near_peers.end(), np);
}
@@ -211,7 +212,8 @@ void Peers::store(const Sha1& sha1)
{
list<Near_peer> near_peers;
get_nearest(sam->get_my_sha1(), PAR_RPCS, near_peers);
for (near_peers_ci i = near_peers.begin(); i != near_peers.end(); i++) {
for (list<Near_peer>::const_iterator i = near_peers.begin();
i != near_peers.end(); i++) {
Rpc rpc(i->get_peer());
rpc.store(sha1);
}

View File

@@ -54,8 +54,6 @@ class Peers {
private:
typedef map<const Sha1, Peer>::const_iterator peersmap_ci;
typedef map<const Sha1, Peer>::iterator peersmap_i;
typedef list<Near_peer>::const_iterator near_peers_ci;
typedef list<Near_peer>::iterator near_peers_i;
void load(void);
void save(void);

View File

@@ -80,8 +80,8 @@ void Rpc::found_peers(const Sha1& sha1)
p++;
*p = near_peers.size();
p++;
for (Peers::near_peers_ci i = near_peers.begin(); i != near_peers.end();
i++) {
for (list<Near_peer>::const_iterator i = near_peers.begin();
i != near_peers.end(); i++) {
const Peer* peer = i->get_peer();
memcpy(p, peer->get_dest().c_str(), (SAM_PUBKEY_LEN - 1));
p += SAM_PUBKEY_LEN - 1;

View File

@@ -42,4 +42,4 @@ class Sam_error {
const samerr_t errcode;
};
#endif // SAM_ERROR_HPP
#endif // SAM_ERROR_HPP

View File

@@ -114,9 +114,9 @@ bool Sha1::operator==(const Sha1& rhs) const
* rhs - sha1 to xor this one with
* result - will be filled with the result
*/
void Sha1::xor(const Sha1& rhs, Bigint& result) const
void Sha1::x_or(const Sha1& rhs, Bigint& result) const
{
Bigint lhsnum(binhashed, SHA1BIN_LEN);
Bigint rhsnum(rhs.binhash(), SHA1BIN_LEN);
lhsnum.xor(rhsnum, result);
lhsnum.x_or(rhsnum, result);
}

View File

@@ -43,7 +43,7 @@ class Sha1 {
bool operator<(const Sha1& rhs) const;
Sha1& operator=(const Sha1& rhs);
bool operator==(const Sha1& rhs) const;
void xor(const Sha1& rhs, Bigint& result) const;
void x_or(const Sha1& rhs, Bigint& result) const;
private:
void b64(void);
@@ -52,4 +52,4 @@ class Sha1 {
uchar_t binhashed[SHA1BIN_LEN]; // non-NUL terminated binary hash
};
#endif // SHA1_HPP
#endif // SHA1_HPP