ほっしーの技術ネタ備忘録

技術ネタの備忘録です。基本的に私が忘れないためのものです。他の人の役にも立つといいなぁ。

namecoin を動かしてみた

めっちゃハマって動かすのに一晩かかったのでメモを残しておく。

  • 以下の pkg をインストールする
autoconf
automake
boost-libs
git-lite
gmake
libevent
libiconv
libtool
pkgconf
# git clone https://github.com/namecoin/namecoin-core.git
  • システムにバンドルされた openssl を pkg-config で参照できるようにするため、以下の2ファイルを作成
    • libcrypto.pc
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: OpenSSL-libssl
Description: Secure Sockets Layer and cryptography libraries
Version: 1.1.0f
Libs: -L${libdir} -lcrypt
Libs.private:
Cflags: -I${includedir}
    • libssl.pc
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: OpenSSL-libssl
Description: Secure Sockets Layer and cryptography libraries
Version: 1.1.0f
Requires.private: libcrypto
Libs: -L${libdir} -lssl
Libs.private:
Cflags: -I${includedir}
  • SSE4.2 のビルドで clang のバグを踏むので、関数ごと削除する
# vim namecoin-core/src/crypto/sha256_sse4.cpp
  • 呼び出し側も削除する
diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp
index 9a21aec20..9debe168d 100644
--- a/src/crypto/sha256.cpp
+++ b/src/crypto/sha256.cpp
@@ -9,16 +9,6 @@
 #include <string.h>
 #include <atomic>

-#if defined(__x86_64__) || defined(__amd64__)
-#if defined(USE_ASM)
-#include <cpuid.h>
-namespace sha256_sse4
-{
-void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
-}
-#endif
-#endif
-
 // Internal implementation code.
 namespace
 {
@@ -178,15 +168,6 @@ TransformType Transform = sha256::Transform;

 std::string SHA256AutoDetect()
 {
-#if defined(USE_ASM) && (defined(__x86_64__) || defined(__amd64__))
-    uint32_t eax, ebx, ecx, edx;
-    if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx >> 19) & 1) {
-        Transform = sha256_sse4::Transform;
-        assert(SelfTest(Transform));
-        return "sse4";
-    }
-#endif
-
     assert(SelfTest(Transform));
     return "standard";
 }
  • ビルドする
# autoreconf --install --force --warnings=all
# ./configure --without-gui --disable-wallet --disable-tests --disable-bench
# gmake
  • rc.d を作る
#!/bin/sh
#

# PROVIDE: namecoind
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="namecoind"
rcvar=namecoind_enable

load_rc_config $name

: ${namecoind_enable="NO"}

namecoin_root="/root/namecoin-core/src"
command="${namecoin_root}/namecoind"
command_args="-daemon"
stop_cmd=namecoind_stop

namecoind_stop()
{
        find_pidfile

        # This duplicates an undesirably large amount of code from the stop
        # routine in rc.subr in order to use rndc to shut down the process,
        # and to give it a second chance in case rndc fails.
        rc_pid=$(check_pidfile ${pidfile} ${command})
        if [ -z "${rc_pid}" ]; then
                [ -n "${rc_fast}" ] && return 0
                _run_rc_notrunning
                return 1
        fi
        echo 'Stopping namecoind.'
        if ${namecoin_root}/namecoin-cli stop; then
                wait_for_pids ${rc_pid}
        else
                echo -n 'namecoin-cli failed, trying kill: '
                kill -TERM ${rc_pid}
                wait_for_pids ${rc_pid}
        fi
}

run_rc_command "$1"