LoginSignup
3
2

More than 1 year has passed since last update.

nostr-relay を改造して event のログを出すところまで

Last updated at Posted at 2023-02-07

概要

軽量 python nostr リレー の nostr-relay を改造して event のログを出すと通信内容が見えて勉強になるかもと思って。

checkout

mkdir nostr-relay
cd nostr-relay
fossil clone https://code.pobblelabs.org/fossil/nostr_relay nostr_relay
fossil open nostr_relay

fossil は git みたいなやつみたい
ぜんぜんわからん
diff すらできんけども。

改造

本当に改造した方が動いてるか確認するために __init__.py を編集してバージョン名を変えとく

nostr_relay/__init__.py
- __version__ =  "1.9.1"
+ __version__ =  "1.9.1.1"

web.py の event を取得してるところで event を全部ログ出力

nostr_relay/web.py
self.log.info(
    "%s added %s from %s", client_id, event.id, event.pubkey
)
+ self.log.info(
+     "event=%s", event
+ )  

ビルド&起動

pip3.9 install -e ./ && nostr-relay serve

結果

  • iris.to とかのクライアントでログイン
  • 設定>nostr>新しいRelay URL に ws://127.0.0.1:6969 と入力して connect ボタンを押す 1
  • そのあと自分のアカウントで「テスト」とかを post してみる
  • (下記のログが見れます)
2023-02-08 01:23:54,986 - nostr_relay.web - INFO - event =
{
    "id":"78e7161490d6a364119a9b46c1c3395aa3b2e9a3f4a6369c62b24dfda839b2c3",
    "pubkey":"4c5d5379a066339c88f6e101e3edb1fbaee4ede3eea35ffc6f1c664b3a4383ee",
    "created_at":1675787034,
    "kind":1,
    "tags":[],
    "content":"テスト",
    "sig":"6236c608e34cf67fac6bf35895c397fe017ef0f040276
        4c82e5b73342edf3d27a0bfba43ea97ffb6743e0a8fb6
        03b61ae54b1b79be3a28871de28432129550ac"
}

もっと通信全部見れるとこあるのかもしれないけど
"REQ" とかも見たいね
cf. https://github.com/nostr-protocol/nips/blob/master/01.md

  1. 他のサーバーが全部 wss:// なのでそれが正しいと思っていたら ws://127.0.0.1:6969 じゃないと通らなかった(s が 1 つ)。syslog:[2023-02-08 00:19:56 +0900] [17683] [WARNING] Invalid HTTP request received. と出るときはそれを要確認。ws と wss は http と https みたいな関係ですね

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2