-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): supporting nip-40. (#96)
- Loading branch information
Showing
13 changed files
with
246 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
# Immortal supported NIPs | ||
|
||
The Immortal follows [NIPs](https://github.com/nostr-protocol/nips) and tries to implement itself as close as possible to this standards. | ||
|
||
- [X] **NIP-01**: Basic Protocol Flow Description | ||
- [ ] **NIP-09**: Event Deletion Request | ||
- [X] **NIP-11**: Relay Information Document | ||
- [X] **NIP-13**: Proof of Work | ||
- [ ] **NIP-40**: Expiration Timestamp | ||
- [X] **NIP-40**: Expiration Timestamp | ||
- [X] **NIP-42**: Authentication of Clients to Relays | ||
- [ ] **NIP-50**: Search Capability | ||
- [ ] **NIP-56**: Reporting | ||
- [X] **NIP-56**: Reporting | ||
- [X] **NIP-70**: Protected Events | ||
- [ ] **NIP-94**: File Metadata | ||
- [ ] **NIP-96**: HTTP File Storage Integration | ||
- [ ] **NIP-98**: HTTP Auth |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/dezh-tech/immortal/types" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func (h *Handler) DeleteByID(id string, kind types.Kind) error { | ||
coll := h.db.Client.Database(h.db.DBName).Collection(getCollectionName(kind)) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), h.db.QueryTimeout) | ||
defer cancel() | ||
|
||
filter := bson.D{ | ||
{Key: "id", Value: id}, | ||
} | ||
|
||
update := bson.D{ | ||
{Key: "$set", Value: bson.D{ | ||
{Key: "id", Value: id}, | ||
}}, | ||
{Key: "$unset", Value: bson.D{ | ||
{Key: "pubkey"}, | ||
{Key: "created_at"}, | ||
{Key: "kind"}, | ||
{Key: "tags"}, | ||
{Key: "content"}, | ||
{Key: "sig"}, | ||
}}, | ||
} | ||
|
||
_, err := coll.UpdateOne(ctx, filter, update) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package websocket | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/dezh-tech/immortal/types" | ||
) | ||
|
||
func (s *Server) checkExpiration() { | ||
for range time.Tick(time.Minute) { | ||
tasks, err := s.redis.GetReadyTasks("expiration_events") | ||
if err != nil { | ||
log.Println("error in checking expired events", err) | ||
} | ||
|
||
failedTasks := make([]string, 0) | ||
|
||
if len(tasks) != 0 { | ||
for _, task := range tasks { | ||
data := strings.Split(task, ":") | ||
|
||
if len(data) != 2 { | ||
continue | ||
} | ||
|
||
kind, err := strconv.Atoi(data[1]) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
if err := s.handler.DeleteByID(data[0], | ||
types.Kind(kind)); err != nil { //nolint | ||
failedTasks = append(failedTasks, task) | ||
} | ||
} | ||
} | ||
|
||
if len(failedTasks) != 0 { | ||
for _, ft := range failedTasks { | ||
if err := s.redis.AddDelayedTask("expiration_events", | ||
ft, time.Minute*10); err != nil { | ||
continue // todo::: retry then send log to manager. | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters