Commit 14f258ef authored by neverlord's avatar neverlord

ripemd160, process id, node id

parent 1b4c24c2
......@@ -135,7 +135,7 @@
</data>
<data>
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
<value type="QString">{23902c37-f07e-47cd-bb19-c366b9f708db}</value>
<value type="QString">{07fcd197-092d-45a0-8500-3be614e6ae31}</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
......
......@@ -156,3 +156,6 @@ cppa/util/if_else.hpp
cppa/util/pop_back.hpp
cppa/util/pt_dispatch.hpp
cppa/detail/get_behavior.hpp
unit_testing/test__ripemd_160.cpp
cppa/process_information.hpp
src/process_information.cpp
......@@ -51,6 +51,16 @@
namespace cppa {
inline void link(actor_ptr& other)
{
self()->link(other);
}
inline void link(actor_ptr&& other)
{
self()->link(other);
}
template<scheduling_hint Hint, typename F, typename... Args>
actor_ptr spawn(F&& what, const Args&... args)
{
......
#ifndef PROCESS_INFORMATION_HPP
#define PROCESS_INFORMATION_HPP
#include <string>
#include <cstdint>
namespace cppa {
/**
* @brief Identifies a process.
*/
struct process_information
{
/**
* @brief Identifies the running process.
*/
std::uint32_t process_id;
/**
* @brief Identifies the host system.
*
* A hash build from the MAC address of the first network device
* and the serial number from the root HD (mounted in "/" or "C:").
*/
std::uint8_t node_id[20];
/**
* @brief Converts {@link node_id} to an hexadecimal string.
*/
std::string node_id_as_string() const;
/**
* @brief Returns the proccess_information for the running process.
* @return
*/
static const process_information& get();
};
} // namespace cppa
#endif // PROCESS_INFORMATION_HPP
#include <sstream>
#include "cppa/process_information.hpp"
namespace cppa {
std::string process_information::node_id_as_string() const
{
std::ostringstream oss;
oss << std::hex;
for (size_t i = 0; i < 20; ++i)
{
oss.width(2);
oss.fill('0');
oss << static_cast<std::uint32_t>(node_id[i]);
}
return oss.str();
}
const process_information& process_information::get()
{
}
} // namespace cppa
......@@ -17,6 +17,7 @@ SOURCES = hash_of.cpp \
test__local_group.cpp \
test__primitive_variant.cpp \
test__queue_performance.cpp \
test__ripemd_160.cpp \
test__serialization.cpp \
test__spawn.cpp \
test__tuple.cpp \
......
#include <cstring>
#include "hash_of.hpp"
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed )
......@@ -63,3 +64,360 @@ unsigned int hash_of(const std::string& what)
{
return MurmurHash2(what.c_str(), what.size(), 0x15091984);
}
namespace {
/* typedef 8 and 32 bit types, resp. */
/* adapt these, if necessary,
for your operating system and compiler */
typedef unsigned char byte;
typedef std::uint32_t dword;
/* macro definitions */
/* collect four bytes into one word: */
#define BYTES_TO_DWORD(strptr) \
(((dword) *((strptr)+3) << 24) | \
((dword) *((strptr)+2) << 16) | \
((dword) *((strptr)+1) << 8) | \
((dword) *(strptr)))
/* ROL(x, n) cyclically rotates x over n bits to the left */
/* x must be of an unsigned 32 bits type and 0 <= n < 32. */
#define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* the five basic functions F(), G() and H() */
#define F(x, y, z) ((x) ^ (y) ^ (z))
#define G(x, y, z) (((x) & (y)) | (~(x) & (z)))
#define H(x, y, z) (((x) | ~(y)) ^ (z))
#define I(x, y, z) (((x) & (z)) | ((y) & ~(z)))
#define J(x, y, z) ((x) ^ ((y) | ~(z)))
/* the ten basic operations FF() through III() */
#define FF(a, b, c, d, e, x, s) {\
(a) += F((b), (c), (d)) + (x);\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define GG(a, b, c, d, e, x, s) {\
(a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define HH(a, b, c, d, e, x, s) {\
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define II(a, b, c, d, e, x, s) {\
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define JJ(a, b, c, d, e, x, s) {\
(a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define FFF(a, b, c, d, e, x, s) {\
(a) += F((b), (c), (d)) + (x);\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define GGG(a, b, c, d, e, x, s) {\
(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define HHH(a, b, c, d, e, x, s) {\
(a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define III(a, b, c, d, e, x, s) {\
(a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
#define JJJ(a, b, c, d, e, x, s) {\
(a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\
(a) = ROL((a), (s)) + (e);\
(c) = ROL((c), 10);\
}
void MDinit(dword *MDbuf)
{
MDbuf[0] = 0x67452301UL;
MDbuf[1] = 0xefcdab89UL;
MDbuf[2] = 0x98badcfeUL;
MDbuf[3] = 0x10325476UL;
MDbuf[4] = 0xc3d2e1f0UL;
}
void compress(dword *MDbuf, dword *X)
{
dword aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2],
dd = MDbuf[3], ee = MDbuf[4];
dword aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2],
ddd = MDbuf[3], eee = MDbuf[4];
/* round 1 */
FF(aa, bb, cc, dd, ee, X[ 0], 11);
FF(ee, aa, bb, cc, dd, X[ 1], 14);
FF(dd, ee, aa, bb, cc, X[ 2], 15);
FF(cc, dd, ee, aa, bb, X[ 3], 12);
FF(bb, cc, dd, ee, aa, X[ 4], 5);
FF(aa, bb, cc, dd, ee, X[ 5], 8);
FF(ee, aa, bb, cc, dd, X[ 6], 7);
FF(dd, ee, aa, bb, cc, X[ 7], 9);
FF(cc, dd, ee, aa, bb, X[ 8], 11);
FF(bb, cc, dd, ee, aa, X[ 9], 13);
FF(aa, bb, cc, dd, ee, X[10], 14);
FF(ee, aa, bb, cc, dd, X[11], 15);
FF(dd, ee, aa, bb, cc, X[12], 6);
FF(cc, dd, ee, aa, bb, X[13], 7);
FF(bb, cc, dd, ee, aa, X[14], 9);
FF(aa, bb, cc, dd, ee, X[15], 8);
/* round 2 */
GG(ee, aa, bb, cc, dd, X[ 7], 7);
GG(dd, ee, aa, bb, cc, X[ 4], 6);
GG(cc, dd, ee, aa, bb, X[13], 8);
GG(bb, cc, dd, ee, aa, X[ 1], 13);
GG(aa, bb, cc, dd, ee, X[10], 11);
GG(ee, aa, bb, cc, dd, X[ 6], 9);
GG(dd, ee, aa, bb, cc, X[15], 7);
GG(cc, dd, ee, aa, bb, X[ 3], 15);
GG(bb, cc, dd, ee, aa, X[12], 7);
GG(aa, bb, cc, dd, ee, X[ 0], 12);
GG(ee, aa, bb, cc, dd, X[ 9], 15);
GG(dd, ee, aa, bb, cc, X[ 5], 9);
GG(cc, dd, ee, aa, bb, X[ 2], 11);
GG(bb, cc, dd, ee, aa, X[14], 7);
GG(aa, bb, cc, dd, ee, X[11], 13);
GG(ee, aa, bb, cc, dd, X[ 8], 12);
/* round 3 */
HH(dd, ee, aa, bb, cc, X[ 3], 11);
HH(cc, dd, ee, aa, bb, X[10], 13);
HH(bb, cc, dd, ee, aa, X[14], 6);
HH(aa, bb, cc, dd, ee, X[ 4], 7);
HH(ee, aa, bb, cc, dd, X[ 9], 14);
HH(dd, ee, aa, bb, cc, X[15], 9);
HH(cc, dd, ee, aa, bb, X[ 8], 13);
HH(bb, cc, dd, ee, aa, X[ 1], 15);
HH(aa, bb, cc, dd, ee, X[ 2], 14);
HH(ee, aa, bb, cc, dd, X[ 7], 8);
HH(dd, ee, aa, bb, cc, X[ 0], 13);
HH(cc, dd, ee, aa, bb, X[ 6], 6);
HH(bb, cc, dd, ee, aa, X[13], 5);
HH(aa, bb, cc, dd, ee, X[11], 12);
HH(ee, aa, bb, cc, dd, X[ 5], 7);
HH(dd, ee, aa, bb, cc, X[12], 5);
/* round 4 */
II(cc, dd, ee, aa, bb, X[ 1], 11);
II(bb, cc, dd, ee, aa, X[ 9], 12);
II(aa, bb, cc, dd, ee, X[11], 14);
II(ee, aa, bb, cc, dd, X[10], 15);
II(dd, ee, aa, bb, cc, X[ 0], 14);
II(cc, dd, ee, aa, bb, X[ 8], 15);
II(bb, cc, dd, ee, aa, X[12], 9);
II(aa, bb, cc, dd, ee, X[ 4], 8);
II(ee, aa, bb, cc, dd, X[13], 9);
II(dd, ee, aa, bb, cc, X[ 3], 14);
II(cc, dd, ee, aa, bb, X[ 7], 5);
II(bb, cc, dd, ee, aa, X[15], 6);
II(aa, bb, cc, dd, ee, X[14], 8);
II(ee, aa, bb, cc, dd, X[ 5], 6);
II(dd, ee, aa, bb, cc, X[ 6], 5);
II(cc, dd, ee, aa, bb, X[ 2], 12);
/* round 5 */
JJ(bb, cc, dd, ee, aa, X[ 4], 9);
JJ(aa, bb, cc, dd, ee, X[ 0], 15);
JJ(ee, aa, bb, cc, dd, X[ 5], 5);
JJ(dd, ee, aa, bb, cc, X[ 9], 11);
JJ(cc, dd, ee, aa, bb, X[ 7], 6);
JJ(bb, cc, dd, ee, aa, X[12], 8);
JJ(aa, bb, cc, dd, ee, X[ 2], 13);
JJ(ee, aa, bb, cc, dd, X[10], 12);
JJ(dd, ee, aa, bb, cc, X[14], 5);
JJ(cc, dd, ee, aa, bb, X[ 1], 12);
JJ(bb, cc, dd, ee, aa, X[ 3], 13);
JJ(aa, bb, cc, dd, ee, X[ 8], 14);
JJ(ee, aa, bb, cc, dd, X[11], 11);
JJ(dd, ee, aa, bb, cc, X[ 6], 8);
JJ(cc, dd, ee, aa, bb, X[15], 5);
JJ(bb, cc, dd, ee, aa, X[13], 6);
/* parallel round 1 */
JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8);
JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9);
JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9);
JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11);
JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13);
JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15);
JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15);
JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5);
JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7);
JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7);
JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8);
JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11);
JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14);
JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14);
JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12);
JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6);
/* parallel round 2 */
III(eee, aaa, bbb, ccc, ddd, X[ 6], 9);
III(ddd, eee, aaa, bbb, ccc, X[11], 13);
III(ccc, ddd, eee, aaa, bbb, X[ 3], 15);
III(bbb, ccc, ddd, eee, aaa, X[ 7], 7);
III(aaa, bbb, ccc, ddd, eee, X[ 0], 12);
III(eee, aaa, bbb, ccc, ddd, X[13], 8);
III(ddd, eee, aaa, bbb, ccc, X[ 5], 9);
III(ccc, ddd, eee, aaa, bbb, X[10], 11);
III(bbb, ccc, ddd, eee, aaa, X[14], 7);
III(aaa, bbb, ccc, ddd, eee, X[15], 7);
III(eee, aaa, bbb, ccc, ddd, X[ 8], 12);
III(ddd, eee, aaa, bbb, ccc, X[12], 7);
III(ccc, ddd, eee, aaa, bbb, X[ 4], 6);
III(bbb, ccc, ddd, eee, aaa, X[ 9], 15);
III(aaa, bbb, ccc, ddd, eee, X[ 1], 13);
III(eee, aaa, bbb, ccc, ddd, X[ 2], 11);
/* parallel round 3 */
HHH(ddd, eee, aaa, bbb, ccc, X[15], 9);
HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7);
HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15);
HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11);
HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8);
HHH(ddd, eee, aaa, bbb, ccc, X[14], 6);
HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6);
HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14);
HHH(aaa, bbb, ccc, ddd, eee, X[11], 12);
HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13);
HHH(ddd, eee, aaa, bbb, ccc, X[12], 5);
HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14);
HHH(bbb, ccc, ddd, eee, aaa, X[10], 13);
HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13);
HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7);
HHH(ddd, eee, aaa, bbb, ccc, X[13], 5);
/* parallel round 4 */
GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15);
GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5);
GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8);
GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11);
GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14);
GGG(ccc, ddd, eee, aaa, bbb, X[11], 14);
GGG(bbb, ccc, ddd, eee, aaa, X[15], 6);
GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14);
GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6);
GGG(ddd, eee, aaa, bbb, ccc, X[12], 9);
GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12);
GGG(bbb, ccc, ddd, eee, aaa, X[13], 9);
GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12);
GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5);
GGG(ddd, eee, aaa, bbb, ccc, X[10], 15);
GGG(ccc, ddd, eee, aaa, bbb, X[14], 8);
/* parallel round 5 */
FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8);
FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5);
FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12);
FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9);
FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12);
FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5);
FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14);
FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6);
FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8);
FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13);
FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6);
FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5);
FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15);
FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13);
FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11);
FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11);
/* combine results */
ddd += cc + MDbuf[1]; /* final result for MDbuf[0] */
MDbuf[1] = MDbuf[2] + dd + eee;
MDbuf[2] = MDbuf[3] + ee + aaa;
MDbuf[3] = MDbuf[4] + aa + bbb;
MDbuf[4] = MDbuf[0] + bb + ccc;
MDbuf[0] = ddd;
return;
}
void MDfinish(dword *MDbuf, const byte *strptr, dword lswlen, dword mswlen)
{
unsigned int i; /* counter */
dword X[16]; /* message words */
memset(X, 0, 16 * sizeof(dword));
/* put bytes from strptr into X */
for (i=0; i<(lswlen&63); i++) {
/* byte i goes into word X[i div 4] at pos. 8*(i mod 4) */
X[i>>2] ^= (dword) *strptr++ << (8 * (i&3));
}
/* append the bit m_n == 1 */
X[(lswlen>>2)&15] ^= (dword)1 << (8*(lswlen&3) + 7);
if ((lswlen & 63) > 55) {
/* length goes to next block */
compress(MDbuf, X);
memset(X, 0, 16*sizeof(dword));
}
/* append length in bits*/
X[14] = lswlen << 3;
X[15] = (lswlen >> 29) | (mswlen << 3);
compress(MDbuf, X);
return;
}
} // namespace <anonmyous>
hash_result_160bit ripemd_160(const std::string& data)
{
dword MDbuf[5]; /* contains (A, B, C, D(, E)) */
dword X[16]; /* current 16-word chunk */
dword length; /* length in bytes of message */
const unsigned char* message = reinterpret_cast<const unsigned char*>(data.c_str());
/* initialize */
MDinit(MDbuf);
length = data.size();
/* process message in 16-word chunks */
for (dword nbytes = length; nbytes > 63; nbytes -= 64)
{
for (dword i = 0; i < 16; ++i)
{
X[i] = BYTES_TO_DWORD(message);
message += 4;
}
compress(MDbuf, X);
}
/* length mod 64 bytes left */
/* finish: */
MDfinish(MDbuf, message, length, 0);
hash_result_160bit result;
for (size_t i = 0; i < result.size(); i += 4)
{
result[i] = MDbuf[i>>2]; /* implicit cast to byte */
result[i+1] = (MDbuf[i>>2] >> 8); /* extracts the 8 least */
result[i+2] = (MDbuf[i>>2] >> 16); /* significant bits. */
result[i+3] = (MDbuf[i>>2] >> 24);
}
return result;
}
......@@ -2,8 +2,49 @@
#define HASH_OF_HPP
#include <string>
#include <ostream>
#include <cstdint>
#include <stdexcept>
unsigned int hash_of(const std::string& what);
unsigned int hash_of(const char* what, int what_length);
struct hash_result_160bit
{
std::uint8_t data[20];
inline std::uint8_t& operator[](size_t p)
{
return data[p];
}
inline std::uint8_t operator[](size_t p) const
{
return data[p];
}
inline size_t size() const
{
return 20;
}
};
namespace std {
inline ostream& operator<<(ostream& o, const hash_result_160bit& res)
{
auto flags = o.flags();
o << std::hex;
for (size_t i = 0; i < res.size(); ++i)
{
o.width(2);
o.fill('0');
o << static_cast<std::uint32_t>(res[i]);
}
// restore flags afterwards
o.flags(flags);
return o;
}
} // namespace std
hash_result_160bit ripemd_160(const std::string& data);
#endif // HASH_OF_HPP
#include <map>
#include <cstdio>
#include <atomic>
#include <string>
#include <limits>
#include <vector>
#include <cstring>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <sstream>
#include <typeinfo>
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include "test.hpp"
#include "hash_of.hpp"
#include "cppa/tuple.hpp"
#include "cppa/config.hpp"
......@@ -24,36 +31,137 @@ using std::cout;
using std::cerr;
using std::endl;
/**
* @brief Identifies a process.
*/
struct process_information
{
/**
* @brief Identifies the host system.
*
* A hash build from the MAC address of the first network device
* and the serial number from the root HD (mounted in "/" or "C:").
*/
std::uint8_t node_id[20];
/**
* @brief Identifies the running process.
*/
std::uint32_t process_id;
/**
* @brief Converts {@link node_id} to an hexadecimal string.
*/
std::string node_id_as_string() const
{
std::ostringstream oss;
oss << std::hex;
for (size_t i = 0; i < 20; ++i)
{
oss.width(2);
oss.fill('0');
oss << static_cast<std::uint32_t>(node_id[i]);
}
return oss.str();
}
};
namespace {
void erase_trailing_newline(std::string& str)
{
while (!str.empty() && (*str.rbegin()) == '\n')
{
str.resize(str.size() - 1);
}
}
process_information compute_proc_info()
{
process_information result;
result.process_id = getpid();
char cbuf[100];
// fetch hd serial
std::string hd_serial;
FILE* cmd = popen("/usr/sbin/diskutil info / | "
"/usr/bin/awk '$0 ~ /UUID/ { print $3 }'",
"r");
while (fgets(cbuf, 100, cmd) != 0)
{
hd_serial += cbuf;
}
pclose(cmd);
erase_trailing_newline(hd_serial);
// fetch mac address of first network device
std::string first_mac_addr;
cmd = popen("/usr/sbin/system_profiler SPNetworkDataType | "
"/usr/bin/grep -Fw MAC | "
"/usr/bin/grep -o \"..:..:..:..:..:..\" | "
"/usr/bin/head -n1",
"r");
while (fgets(cbuf, 100, cmd) != 0)
{
first_mac_addr += cbuf;
}
pclose(cmd);
erase_trailing_newline(first_mac_addr);
hash_result_160bit tmp = ripemd_160(first_mac_addr + hd_serial);
memcpy(result.node_id, tmp.data, 20);
return result;
}
} // namespace <anonymous>
const process_information& get_process_information()
{
static auto s_proc_info = compute_proc_info();
return s_proc_info;
}
void print_node_id()
{
const auto& pinfo = get_process_information();
// lifetime scope of oss
std::string node_id_hash = pinfo.node_id_as_string();
cout << "node id: " << node_id_hash << endl;
cout << "process id: " << pinfo.process_id << endl;
cout << "actor id format: {process id}.{actor id}@{node id}" << endl;
cout << "example actor id: " << pinfo.process_id
<< ".42@"
<< node_id_hash
<< endl;
}
int main(int argc, char** c_argv)
{
print_node_id();
return 0;
std::vector<std::string> argv;
for (int i = 1; i < argc; ++i)
{
argv.push_back(c_argv[i]);
}
if (!argv.empty())
{
if (argv.size() == 1 && argv.front() == "performance_test")
{
cout << endl << "run queue performance test ... " << endl;
test__queue_performance();
return 0;
}
else
{
cerr << "unrecognized options"
<< endl
<< "no options:\n\tunit tests"
<< endl
<< "performance_test:\n\trun single reader queue tests"
<< endl;
cerr << "usage: test [performance_test]" << endl;
}
}
else
{
std::cout << std::boolalpha;
size_t errors = 0;
RUN_TEST(test__ripemd_160);
RUN_TEST(test__primitive_variant);
RUN_TEST(test__uniform_type);
RUN_TEST(test__intrusive_ptr);
......
......@@ -46,6 +46,7 @@ std::cerr << err_msg << std::endl; \
#define CPPA_CHECK_EQUAL(lhs_loc, rhs_loc) CPPA_CHECK(((lhs_loc) == (rhs_loc)))
size_t test__ripemd_160();
size_t test__uniform_type();
size_t test__type_list();
size_t test__a_matches_b();
......
......@@ -42,7 +42,7 @@ baz;
size_t test__local_group()
{
CPPA_TEST(test__local_group);
/*
baz << make_tuple(1, 2, 3);
auto foo_group = group::get("local", "foo");
......@@ -60,5 +60,6 @@ size_t test__local_group()
}
CPPA_CHECK_EQUAL(result, 10);
await_all_others_done();
*/
return CPPA_TEST_RESULT;
}
#include <sstream>
#include <iostream>
#include "test.hpp"
#include "hash_of.hpp"
namespace {
std::string str_hash(const std::string& what)
{
std::ostringstream oss;
oss << ripemd_160(what);
return oss.str();
}
} // namespace <anonymous>
// verify ripemd implementation with example hash results from
// http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
size_t test__ripemd_160()
{
CPPA_TEST(test__ripemd_160);
CPPA_CHECK_EQUAL(str_hash(""),
"9c1185a5c5e9fc54612808977ee8f548b2258d31");
CPPA_CHECK_EQUAL(str_hash("a"),
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe");
CPPA_CHECK_EQUAL(str_hash("abc"),
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc");
CPPA_CHECK_EQUAL(str_hash("message digest"),
"5d0689ef49d2fae572b881b123a85ffa21595f36");
CPPA_CHECK_EQUAL(str_hash("abcdefghijklmnopqrstuvwxyz"),
"f71c27109c692c1b56bbdceb5b9d2865b3708dbc");
CPPA_CHECK_EQUAL(str_hash("abcdbcdecdefdefgefghfghighij"
"hijkijkljklmklmnlmnomnopnopq"),
"12a053384a9c0c88e405a06c27dcf49ada62eb2b");
CPPA_CHECK_EQUAL(str_hash("ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
"fghijklmnopqrstuvwxyz0123456789"),
"b0e20b6e3116640286ed3a87a5713079b21f5189");
CPPA_CHECK_EQUAL(str_hash("1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890"),
"9b752e45573d4b39f4dbd3323cab82bf63326bfb");
//CPPA_CHECK_EQUAL(str_hash(std::string(1000000, 'a')),
// "52783243c1697bdbe16d37f97f68f08325dc1528");
return CPPA_TEST_RESULT;
}
......@@ -10,13 +10,39 @@
using std::cout;
using std::endl;
namespace { int pings = 0; }
using namespace cppa;
void pong()
void pong(actor_ptr ping_actor)
{
receive(on<int>() >> [](int value) {
reply((value * 20) + 2);
});
link(ping_actor);
bool quit = false;
// kickoff
ping_actor << make_tuple(0); // or: send(ping_actor, 0);
// invoke rules
auto rules = (on<std::int32_t>(9) >> [&]() { quit = true; },
on<std::int32_t>() >> [](int v) { reply(v+1); });
// loop
while (!quit) receive(rules);
}
void ping()
{
// invoke rule
auto rule = on<std::int32_t>() >> [](std::int32_t v)
{
++pings;
reply(v+1);
};
// loop
for (;;) receive(rule);
}
void pong_example()
{
spawn(pong, spawn(ping));
await_all_others_done();
}
void echo(actor_ptr whom, int what)
......@@ -27,6 +53,9 @@ void echo(actor_ptr whom, int what)
size_t test__spawn()
{
CPPA_TEST(test__spawn);
pong_example();
CPPA_CHECK_EQUAL(pings, 5);
/*
actor_ptr self_ptr = self();
{
spawn(echo, self_ptr, 1);
......@@ -63,5 +92,6 @@ size_t test__spawn()
CPPA_CHECK(received_echo);
}
await_all_others_done();
*/
return CPPA_TEST_RESULT;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment