Skip to content

Commit

Permalink
Merge branch 'master' into feat/autoshard-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem authored Sep 18, 2023
2 parents c127322 + fb2df14 commit 5a37761
Show file tree
Hide file tree
Showing 70 changed files with 640 additions and 337 deletions.
4 changes: 0 additions & 4 deletions .golangci.full.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
run:
build-tags:
- gowaku_rln

issues:
include:
- EXC0012
Expand Down
3 changes: 0 additions & 3 deletions .golangci.yaml

This file was deleted.

11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# BUILD IMAGE --------------------------------------------------------
FROM golang:1.19-alpine3.16 as builder

# Get build tools and required header files
RUN apk add --no-cache build-base
RUN apk add --no-cache bash
RUN apk add --no-cache git
FROM golang:1.19 as builder

WORKDIR /app
COPY . .
Expand All @@ -14,7 +9,7 @@ RUN make -j$(nproc) build

# ACTUAL IMAGE -------------------------------------------------------

FROM alpine:3.16
FROM debian:12.1-slim

ARG GIT_COMMIT=unknown

Expand All @@ -26,6 +21,8 @@ LABEL commit=$GIT_COMMIT
# color, nocolor, json
ENV GOLOG_LOG_FMT=nocolor

RUN apt update && apt install -y ca-certificates

# go-waku default ports
EXPOSE 9000 30303 60000 60001 8008 8009

Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ BUILD_FLAGS ?= $(shell echo "-ldflags='\
ANDROID_TARGET ?= 23

# control rln code compilation
ifeq ($(RLN), true)
BUILD_TAGS := gowaku_rln
ifeq ($(NO_RLN), true)
BUILD_TAGS := gowaku_no_rln
endif

all: build
Expand All @@ -58,7 +58,7 @@ build:

chat2:
pushd ./examples/chat2 && \
${GOBIN} build -tags="gowaku_rln" -o ../../build/chat2 . && \
${GOBIN} build -o ../../build/chat2 . && \
popd

vendor:
Expand Down Expand Up @@ -124,13 +124,16 @@ build-example-filter2:
build-example-c-bindings:
cd examples/c-bindings && $(MAKE)

build-example: build-example-basic2 build-example-chat-2 build-example-filter2 build-example-c-bindings
build-example-rln:
cd examples/rln && $(MAKE)

build-example: build-example-basic2 build-example-chat-2 build-example-filter2 build-example-c-bindings build-example-rln

static-library:
@echo "Building static library..."
${GOBIN} build \
-buildmode=c-archive \
-tags="${BUILD_TAGS}" \
-tags="${BUILD_TAGS} gowaku_no_rln" \
-o ./build/lib/libgowaku.a \
./library/c/
@echo "Static library built:"
Expand All @@ -146,7 +149,7 @@ dynamic-library:
rm -f ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT)*
$(GOBIN_SHARED_LIB_CFLAGS) $(GOBIN_SHARED_LIB_CGO_LDFLAGS) ${GOBIN} build \
-buildmode=c-shared \
-tags="${BUILD_TAGS}" \
-tags="${BUILD_TAGS} gowaku_no_rln" \
-o ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT) \
./library/c/
ifeq ($(detected_OS),Darwin)
Expand All @@ -166,14 +169,14 @@ mobile-android:
@echo "Android target: ${ANDROID_TARGET} (override with ANDROID_TARGET var)"
gomobile init && \
${GOBIN} get -d golang.org/x/mobile/cmd/gomobile && \
gomobile bind -v -target=android -androidapi=${ANDROID_TARGET} -ldflags="-s -w" -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o ./build/lib/gowaku.aar ./library/mobile
CGO=1 gomobile bind -v -target=android -androidapi=${ANDROID_TARGET} -ldflags="-s -w" -tags="${BUILD_TAGS} gowaku_no_rln" $(BUILD_FLAGS) -o ./build/lib/gowaku.aar ./library/mobile
@echo "Android library built:"
@ls -la ./build/lib/*.aar ./build/lib/*.jar

mobile-ios:
gomobile init && \
${GOBIN} get -d golang.org/x/mobile/cmd/gomobile && \
gomobile bind -target=ios -ldflags="-s -w" -tags="nowatchdog ${BUILD_TAGS}" $(BUILD_FLAGS) -o ./build/lib/Gowaku.xcframework ./library/mobile
gomobile bind -target=ios -ldflags="-s -w" -tags="nowatchdog ${BUILD_TAGS} gowaku_no_rln" $(BUILD_FLAGS) -o ./build/lib/Gowaku.xcframework ./library/mobile
@echo "IOS library built:"
@ls -la ./build/lib/*.xcframework

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A Go implementation of the [Waku v2 protocol](https://rfc.vac.dev/spec/10).
<p align="left">
<a href="https://goreportcard.com/report/github.com/waku-org/go-waku"><img src="https://goreportcard.com/badge/github.com/waku-org/go-waku" /></a>
<a href="https://godoc.org/github.com/waku-org/go-waku"><img src="http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square" /></a>
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.18.0-orange.svg?style=flat-square" /></a>
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.19.0-orange.svg?style=flat-square" /></a>
<a href="https://codeclimate.com/github/waku-org/go-waku/maintainability"><img src="https://api.codeclimate.com/v1/badges/426bdff6a339ff4d536b/maintainability" /></a>
<br>
</p>
Expand Down Expand Up @@ -38,7 +38,7 @@ nix develop
#### Docker
```
docker run -i -t -p 60000:60000 -p 9000:9000/udp \
statusteam/go-waku:v0.5.2 \ # or, the image:tag of your choice
statusteam/go-waku:latest \ # or, the image:tag of your choice
--dns-discovery:true \
--dns-discovery-url:enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.waku.nodes.status.im \
--discv5-discovery
Expand All @@ -47,9 +47,9 @@ docker run -i -t -p 60000:60000 -p 9000:9000/udp \
or build and run the image with:

```
docker build -t go-waku:latest .
docker build -t statusteam/go-waku:latest .
docker run go-waku:latest --help
docker run statusteam/go-waku:latest --help
```

#### Building on windows
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0
0.8.0
4 changes: 2 additions & 2 deletions cmd/waku/flags_no_rln.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !gowaku_rln
// +build !gowaku_rln
//go:build gowaku_no_rln
// +build gowaku_no_rln

package main

Expand Down
9 changes: 4 additions & 5 deletions cmd/waku/flags_rln.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//go:build gowaku_rln
// +build gowaku_rln
//go:build !gowaku_no_rln
// +build !gowaku_no_rln

package main

import (
cli "github.com/urfave/cli/v2"
wcli "github.com/waku-org/go-waku/waku/cliutils"
"github.com/waku-org/go-waku/waku/v2/protocol/rln/keystore"
)

func rlnFlags() []cli.Flag {
Expand All @@ -32,12 +31,12 @@ func rlnFlags() []cli.Flag {
&cli.PathFlag{
Name: "rln-relay-cred-path",
Usage: "RLN relay membership credentials file",
Value: keystore.DefaultCredentialsFilename,
Value: "",
Destination: &options.RLNRelay.CredentialsPath,
},
&cli.StringFlag{
Name: "rln-relay-cred-password",
Value: keystore.DefaultCredentialsPassword,
Value: "",
Usage: "Password for encrypting RLN credentials",
Destination: &options.RLNRelay.CredentialsPassword,
},
Expand Down
29 changes: 17 additions & 12 deletions cmd/waku/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,26 +300,30 @@ func Execute(options NodeOptions) {
utils.Logger().Info("Version details ", zap.String("version", node.Version), zap.String("commit", node.GitCommit))

failOnErr(err, "Wakunode")
//Process pubSub and contentTopics specified and arrive at all corresponding pubSubTopics
pubSubTopicMap := processTopics(options)
pubSubTopicMapKeys := make([]string, 0, len(pubSubTopicMap))
for k := range pubSubTopicMap {
pubSubTopicMapKeys = append(pubSubTopicMapKeys, k)
}

if options.Filter.UseV1 {
addStaticPeers(wakuNode, options.Filter.NodesV1, legacy_filter.FilterID_v20beta1)
addStaticPeers(wakuNode, options.Filter.NodesV1, pubSubTopicMapKeys, legacy_filter.FilterID_v20beta1)
}

//Process pubSub and contentTopics specified and arrive at all corresponding pubSubTopics
pubSubTopicMap := processTopics(options)

if err = wakuNode.Start(ctx); err != nil {
logger.Fatal("starting waku node", zap.Error(err))
}

for _, d := range discoveredNodes {
wakuNode.AddDiscoveredPeer(d.PeerID, d.PeerInfo.Addrs, wakupeerstore.DNSDiscovery)
wakuNode.AddDiscoveredPeer(d.PeerID, d.PeerInfo.Addrs, wakupeerstore.DNSDiscovery, nil)
}

addStaticPeers(wakuNode, options.Store.Nodes, store.StoreID_v20beta4)
addStaticPeers(wakuNode, options.LightPush.Nodes, lightpush.LightPushID_v20beta1)
addStaticPeers(wakuNode, options.Rendezvous.Nodes, rendezvous.RendezvousID)
addStaticPeers(wakuNode, options.Filter.Nodes, filter.FilterSubscribeID_v20beta1)
//For now assuming that static peers added support/listen on all topics specified via commandLine.
addStaticPeers(wakuNode, options.Store.Nodes, pubSubTopicMapKeys, store.StoreID_v20beta4)
addStaticPeers(wakuNode, options.LightPush.Nodes, pubSubTopicMapKeys, lightpush.LightPushID_v20beta1)
addStaticPeers(wakuNode, options.Rendezvous.Nodes, pubSubTopicMapKeys, rendezvous.RendezvousID)
addStaticPeers(wakuNode, options.Filter.Nodes, pubSubTopicMapKeys, filter.FilterSubscribeID_v20beta1)

var wg sync.WaitGroup

Expand Down Expand Up @@ -409,7 +413,8 @@ func Execute(options NodeOptions) {
if options.PeerExchange.Enable && options.PeerExchange.Node != nil {
logger.Info("retrieving peer info via peer exchange protocol")

peerID, err := wakuNode.AddPeer(*options.PeerExchange.Node, wakupeerstore.Static, peer_exchange.PeerExchangeID_v20alpha1)
peerID, err := wakuNode.AddPeer(*options.PeerExchange.Node, wakupeerstore.Static,
pubSubTopicMapKeys, peer_exchange.PeerExchangeID_v20alpha1)
if err != nil {
logger.Error("adding peer exchange peer", logging.MultiAddrs("node", *options.PeerExchange.Node), zap.Error(err))
} else {
Expand Down Expand Up @@ -510,9 +515,9 @@ func processTopics(options NodeOptions) map[string]struct{} {
return pubSubTopicMap
}

func addStaticPeers(wakuNode *node.WakuNode, addresses []multiaddr.Multiaddr, protocols ...protocol.ID) {
func addStaticPeers(wakuNode *node.WakuNode, addresses []multiaddr.Multiaddr, pubSubTopics []string, protocols ...protocol.ID) {
for _, addr := range addresses {
_, err := wakuNode.AddPeer(addr, wakupeerstore.Static, protocols...)
_, err := wakuNode.AddPeer(addr, wakupeerstore.Static, pubSubTopics, protocols...)
failOnErr(err, "error adding peer")
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/waku/node_no_rln.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !gowaku_rln
// +build !gowaku_rln
//go:build gowaku_no_rln
// +build gowaku_no_rln

package main

Expand Down
4 changes: 2 additions & 2 deletions cmd/waku/node_rln.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build gowaku_rln
// +build gowaku_rln
//go:build !gowaku_no_rln
// +build !gowaku_no_rln

package main

Expand Down
4 changes: 2 additions & 2 deletions cmd/waku/rlngenerate/command_no_rln.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !gowaku_rln
// +build !gowaku_rln
//go:build gowaku_no_rln
// +build gowaku_no_rln

package rlngenerate

Expand Down
4 changes: 2 additions & 2 deletions cmd/waku/rlngenerate/command_rln.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build gowaku_rln
// +build gowaku_rln
//go:build !gowaku_no_rln
// +build !gowaku_no_rln

package rlngenerate

Expand Down
7 changes: 3 additions & 4 deletions cmd/waku/rlngenerate/flags.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
//go:build gowaku_rln
// +build gowaku_rln
//go:build !gowaku_no_rln
// +build !gowaku_no_rln

package rlngenerate

import (
cli "github.com/urfave/cli/v2"
wcli "github.com/waku-org/go-waku/waku/cliutils"
"github.com/waku-org/go-waku/waku/v2/protocol/rln/keystore"
)

var flags = []cli.Flag{
&cli.PathFlag{
Name: "cred-path",
Usage: "RLN relay membership credentials file",
Value: keystore.DefaultCredentialsFilename,
Value: "./rlnKeystore.json",
Destination: &options.CredentialsPath,
},
&cli.StringFlag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/waku/rlngenerate/web3.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build gowaku_rln
// +build gowaku_rln
//go:build !gowaku_no_rln
// +build !gowaku_no_rln

package rlngenerate

Expand Down
4 changes: 2 additions & 2 deletions cmd/waku/server/no_rln.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !gowaku_rln
// +build !gowaku_rln
//go:build gowaku_no_rln
// +build gowaku_no_rln

package server

Expand Down
48 changes: 48 additions & 0 deletions cmd/waku/server/rest/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package rest

import (
"context"
"errors"
"net/http"

"github.com/go-chi/chi/v5"
"github.com/waku-org/go-waku/waku/v2/node"
)

type HealthService struct {
node *node.WakuNode
mux *chi.Mux
}

const routeHealth = "/health"

func NewHealthService(node *node.WakuNode, m *chi.Mux) *HealthService {
h := &HealthService{
node: node,
mux: m,
}

m.Get(routeHealth, h.getHealth)

return h
}

type HealthResponse string

func (d *HealthService) getHealth(w http.ResponseWriter, r *http.Request) {
isReady, err := d.node.RLNRelay().IsReady(r.Context())
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
writeResponse(w, HealthResponse("Health check timed out"), http.StatusInternalServerError)
} else {
writeResponse(w, HealthResponse(err.Error()), http.StatusInternalServerError)
}
return
}

if isReady {
writeResponse(w, HealthResponse("Node is healthy"), http.StatusOK)
} else {
writeResponse(w, HealthResponse("Node is not ready"), http.StatusInternalServerError)
}
}
Loading

0 comments on commit 5a37761

Please sign in to comment.