mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-06 05:00:33 +02:00
slight improvements to debug logging.
This commit is contained in:
10
relay.go
10
relay.go
@@ -160,6 +160,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case "NOTICE":
|
case "NOTICE":
|
||||||
|
DebugLogger.Printf("{%s} %v\n", r.URL, jsonMessage)
|
||||||
var content string
|
var content string
|
||||||
json.Unmarshal(jsonMessage[1], &content)
|
json.Unmarshal(jsonMessage[1], &content)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -170,6 +171,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
r.mutex.RUnlock()
|
r.mutex.RUnlock()
|
||||||
}()
|
}()
|
||||||
case "AUTH":
|
case "AUTH":
|
||||||
|
DebugLogger.Printf("{%s} %v\n", r.URL, jsonMessage)
|
||||||
var challenge string
|
var challenge string
|
||||||
json.Unmarshal(jsonMessage[1], &challenge)
|
json.Unmarshal(jsonMessage[1], &challenge)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -226,6 +228,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
if len(jsonMessage) < 2 {
|
if len(jsonMessage) < 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
DebugLogger.Printf("{%s} %v\n", r.URL, jsonMessage)
|
||||||
var subId string
|
var subId string
|
||||||
json.Unmarshal(jsonMessage[1], &subId)
|
json.Unmarshal(jsonMessage[1], &subId)
|
||||||
if subscription, ok := r.subscriptions.Load(subId); ok {
|
if subscription, ok := r.subscriptions.Load(subId); ok {
|
||||||
@@ -237,6 +240,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
if len(jsonMessage) < 3 {
|
if len(jsonMessage) < 3 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
DebugLogger.Printf("{%s} %v\n", r.URL, jsonMessage)
|
||||||
var (
|
var (
|
||||||
eventId string
|
eventId string
|
||||||
ok bool
|
ok bool
|
||||||
@@ -249,8 +253,6 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
json.Unmarshal(jsonMessage[3], &msg)
|
json.Unmarshal(jsonMessage[3], &msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.Printf("{%s} OK: %s %v %s\n", r.URL, eventId, ok, msg)
|
|
||||||
|
|
||||||
if okCallback, exist := r.okCallbacks.Load(eventId); exist {
|
if okCallback, exist := r.okCallbacks.Load(eventId); exist {
|
||||||
okCallback(ok, msg)
|
okCallback(ok, msg)
|
||||||
}
|
}
|
||||||
@@ -373,7 +375,9 @@ func (r *Relay) Auth(ctx context.Context, event Event) (Status, error) {
|
|||||||
defer r.okCallbacks.Delete(event.ID)
|
defer r.okCallbacks.Delete(event.ID)
|
||||||
|
|
||||||
// send AUTH
|
// send AUTH
|
||||||
if err := r.Connection.WriteJSON([]interface{}{"AUTH", event}); err != nil {
|
authResponse := []interface{}{"AUTH", event}
|
||||||
|
DebugLogger.Printf("{%s} sending %v\n", r.URL, authResponse)
|
||||||
|
if err := r.Connection.WriteJSON(authResponse); err != nil {
|
||||||
// status will be "failed"
|
// status will be "failed"
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
@@ -68,7 +68,7 @@ func (sub *Subscription) Fire() error {
|
|||||||
message = append(message, filter)
|
message = append(message, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugLogger.Printf("{%s} REQ: %v", sub.Relay.URL, message)
|
DebugLogger.Printf("{%s} sending %v", sub.Relay.URL, message)
|
||||||
|
|
||||||
err := sub.conn.WriteJSON(message)
|
err := sub.conn.WriteJSON(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
// test if we can connect to wss://relay.damus.io and fetch a couple of random events
|
// test if we can connect to wss://relay.damus.io and fetch a couple of random events
|
||||||
func TestSubscribe(t *testing.T) {
|
func TestSubscribe(t *testing.T) {
|
||||||
rl := mustRelayConnect("wss://relay.damus.io")
|
rl := mustRelayConnect("wss://relay.damus.io")
|
||||||
defer rl.Close("")
|
defer rl.Close()
|
||||||
|
|
||||||
sub, err := rl.Subscribe(context.Background(), Filters{{Kinds: []int{1}, Limit: 2}})
|
sub, err := rl.Subscribe(context.Background(), Filters{{Kinds: []int{1}, Limit: 2}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user