-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from waku-org/feat/waku-message-sequence
Track message sequences for Waku dogfooding
- Loading branch information
Showing
7 changed files
with
171 additions
and
2 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 |
---|---|---|
|
@@ -14,6 +14,16 @@ Then you can run the server with: | |
go run cmd/server/main.go -data-source-name postgres://telemetry:[email protected]:5432/telemetry | ||
``` | ||
|
||
If trying to run locally you receive the following error: | ||
``` | ||
pq: SSL is not enabled on the server | ||
``` | ||
|
||
Run this command instead: | ||
``` | ||
go run cmd/server/main.go -data-source-name "postgres://telemetry:[email protected]:5432/telemetry?sslmode=disable" | ||
``` | ||
|
||
Finally, to run the test: | ||
``` | ||
make test | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,15 @@ | ||
CREATE TABLE IF NOT EXISTS wakuPushFilter ( | ||
id SERIAL PRIMARY KEY, | ||
walletAddress VARCHAR(255), | ||
peerIdSender VARCHAR(255) NOT NULL, | ||
peerIdReporter VARCHAR(255) NOT NULL, | ||
sequenceHash VARCHAR(255) NOT NULL, | ||
sequenceTotal VARCHAR(255) NOT NULL, | ||
sequenceIndex VARCHAR(255) NOT NULL, | ||
contentTopic VARCHAR(255) NOT NULL, | ||
pubsubTopic VARCHAR(255) NOT NULL, | ||
timestamp INTEGER NOT NULL, | ||
createdAt INTEGER NOT NULL, | ||
|
||
CONSTRAINT wakuPushFilter_unique unique(peerIdSender, peerIdReporter, sequenceHash, sequenceIndex) | ||
); |
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,52 @@ | ||
package telemetry | ||
|
||
import ( | ||
"database/sql" | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
type WakuTelemetryType string | ||
|
||
const ( | ||
LightPushFilter WakuTelemetryType = "LightPushFilter" | ||
) | ||
|
||
type WakuTelemetryRequest struct { | ||
Id int `json:"id"` | ||
TelemetryType WakuTelemetryType `json:"telemetryType"` | ||
TelemetryData *json.RawMessage `json:"telemetryData"` | ||
} | ||
|
||
type TelemetryPushFilter struct { | ||
ID int `json:"id"` | ||
WalletAddress string `json:"walletAddress"` | ||
PeerIDSender string `json:"peerIdSender"` | ||
PeerIDReporter string `json:"peerIdReporter"` | ||
SequenceHash string `json:"sequenceHash"` | ||
SequenceTotal uint64 `json:"sequenceTotal"` | ||
SequenceIndex uint64 `json:"sequenceIndex"` | ||
ContentTopic string `json:"contentTopic"` | ||
PubsubTopic string `json:"pubsubTopic"` | ||
Timestamp int64 `json:"timestamp"` | ||
CreatedAt int64 `json:"createdAt"` | ||
} | ||
|
||
func (r *TelemetryPushFilter) put(db *sql.DB) error { | ||
stmt, err := db.Prepare("INSERT INTO wakuPushFilter (peerIdSender, peerIdReporter, sequenceHash, sequenceTotal, sequenceIndex, contentTopic, pubsubTopic, timestamp, createdAt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer stmt.Close() | ||
|
||
r.CreatedAt = time.Now().Unix() | ||
lastInsertId := 0 | ||
err = stmt.QueryRow(r.PeerIDSender, r.PeerIDReporter, r.SequenceHash, r.SequenceTotal, r.SequenceIndex, r.ContentTopic, r.PubsubTopic, r.Timestamp, r.CreatedAt).Scan(&lastInsertId) | ||
if err != nil { | ||
return err | ||
} | ||
r.ID = lastInsertId | ||
|
||
return nil | ||
} |