mirror of https://github.com/status-im/go-waku.git
feat: set log level
This commit is contained in:
parent
e393b68ab7
commit
a231a043b6
|
@ -15,7 +15,6 @@ import (
|
|||
|
||||
func main() {}
|
||||
|
||||
//export waku_new
|
||||
// Initialize a waku node. Receives a JSON string containing the configuration
|
||||
// for the node. It can be NULL. Example configuration:
|
||||
// ```
|
||||
|
@ -30,123 +29,143 @@ func main() {}
|
|||
// - relay: Enable WakuRelay. Default `true`
|
||||
// - minPeersToPublish: The minimum number of peers required on a topic to allow broadcasting a message. Default `0`
|
||||
// - filter: Enable Filter. Default `false`
|
||||
// - logLevel: Set the log level. Default `INFO`. Allowed values "DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL"
|
||||
//
|
||||
//export waku_new
|
||||
func waku_new(configJSON *C.char) *C.char {
|
||||
response := mobile.NewNode(C.GoString(configJSON))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_start
|
||||
// Starts the waku node
|
||||
//
|
||||
//export waku_start
|
||||
func waku_start() *C.char {
|
||||
response := mobile.Start()
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_stop
|
||||
// Stops a waku node
|
||||
//
|
||||
//export waku_stop
|
||||
func waku_stop() *C.char {
|
||||
response := mobile.Stop()
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_is_started
|
||||
// Determine is a node is started or not
|
||||
//
|
||||
//export waku_is_started
|
||||
func waku_is_started() *C.char {
|
||||
response := mobile.IsStarted()
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_peerid
|
||||
// Obtain the peer ID of the waku node
|
||||
//
|
||||
//export waku_peerid
|
||||
func waku_peerid() *C.char {
|
||||
response := mobile.PeerID()
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_listen_addresses
|
||||
// Obtain the multiaddresses the wakunode is listening to
|
||||
//
|
||||
//export waku_listen_addresses
|
||||
func waku_listen_addresses() *C.char {
|
||||
response := mobile.ListenAddresses()
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_add_peer
|
||||
// Add node multiaddress and protocol to the wakunode peerstore
|
||||
//
|
||||
//export waku_add_peer
|
||||
func waku_add_peer(address *C.char, protocolID *C.char) *C.char {
|
||||
response := mobile.AddPeer(C.GoString(address), C.GoString(protocolID))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_connect
|
||||
// Connect to peer at multiaddress. if ms > 0, cancel the function execution if it takes longer than N milliseconds
|
||||
//
|
||||
//export waku_connect
|
||||
func waku_connect(address *C.char, ms C.int) *C.char {
|
||||
response := mobile.Connect(C.GoString(address), int(ms))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_connect_peerid
|
||||
// Connect to known peer by peerID. if ms > 0, cancel the function execution if it takes longer than N milliseconds
|
||||
//
|
||||
//export waku_connect_peerid
|
||||
func waku_connect_peerid(peerID *C.char, ms C.int) *C.char {
|
||||
response := mobile.ConnectPeerID(C.GoString(peerID), int(ms))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_disconnect
|
||||
// Close connection to a known peer by peerID
|
||||
//
|
||||
//export waku_disconnect
|
||||
func waku_disconnect(peerID *C.char) *C.char {
|
||||
response := mobile.Disconnect(C.GoString(peerID))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_peer_cnt
|
||||
// Get number of connected peers
|
||||
//
|
||||
//export waku_peer_cnt
|
||||
func waku_peer_cnt() *C.char {
|
||||
response := mobile.PeerCnt()
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_content_topic
|
||||
// Create a content topic string according to RFC 23
|
||||
//
|
||||
//export waku_content_topic
|
||||
func waku_content_topic(applicationName *C.char, applicationVersion C.uint, contentTopicName *C.char, encoding *C.char) *C.char {
|
||||
return C.CString(protocol.NewContentTopic(C.GoString(applicationName), uint(applicationVersion), C.GoString(contentTopicName), C.GoString(encoding)).String())
|
||||
}
|
||||
|
||||
//export waku_pubsub_topic
|
||||
// Create a pubsub topic string according to RFC 23
|
||||
//
|
||||
//export waku_pubsub_topic
|
||||
func waku_pubsub_topic(name *C.char, encoding *C.char) *C.char {
|
||||
return C.CString(mobile.PubsubTopic(C.GoString(name), C.GoString(encoding)))
|
||||
}
|
||||
|
||||
//export waku_default_pubsub_topic
|
||||
// Get the default pubsub topic used in waku2: /waku/2/default-waku/proto
|
||||
//
|
||||
//export waku_default_pubsub_topic
|
||||
func waku_default_pubsub_topic() *C.char {
|
||||
return C.CString(mobile.DefaultPubsubTopic())
|
||||
}
|
||||
|
||||
//export waku_set_event_callback
|
||||
// Register callback to act as signal handler and receive application signals
|
||||
// (in JSON) which are used to react to asynchronous events in waku. The function
|
||||
// signature for the callback should be `void myCallback(char* signalJSON)`
|
||||
//
|
||||
//export waku_set_event_callback
|
||||
func waku_set_event_callback(cb unsafe.Pointer) {
|
||||
mobile.SetEventCallback(cb)
|
||||
}
|
||||
|
||||
//export waku_peers
|
||||
// Retrieve the list of peers known by the waku node
|
||||
//
|
||||
//export waku_peers
|
||||
func waku_peers() *C.char {
|
||||
response := mobile.Peers()
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_decode_symmetric
|
||||
// Decode a waku message using a 32 bytes symmetric key. The key must be a hex encoded string with "0x" prefix
|
||||
//
|
||||
//export waku_decode_symmetric
|
||||
func waku_decode_symmetric(messageJSON *C.char, symmetricKey *C.char) *C.char {
|
||||
response := mobile.DecodeSymmetric(C.GoString(messageJSON), C.GoString(symmetricKey))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
//export waku_decode_asymmetric
|
||||
// Decode a waku message using a secp256k1 private key. The key must be a hex encoded string with "0x" prefix
|
||||
//
|
||||
//export waku_decode_asymmetric
|
||||
func waku_decode_asymmetric(messageJSON *C.char, privateKey *C.char) *C.char {
|
||||
response := mobile.DecodeAsymmetric(C.GoString(messageJSON), C.GoString(privateKey))
|
||||
return C.CString(response)
|
||||
|
|
|
@ -14,6 +14,8 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
logging "github.com/ipfs/go-log"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||
|
@ -43,6 +45,7 @@ type wakuConfig struct {
|
|||
Port *int `json:"port,omitempty"`
|
||||
AdvertiseAddress *string `json:"advertiseAddr,omitempty"`
|
||||
NodeKey *string `json:"nodeKey,omitempty"`
|
||||
LogLevel *string `json:"logLevel,omitempty"`
|
||||
KeepAliveInterval *int `json:"keepAliveInterval,omitempty"`
|
||||
EnableRelay *bool `json:"relay"`
|
||||
EnableFilter *bool `json:"filter"`
|
||||
|
@ -55,6 +58,7 @@ var defaultKeepAliveInterval = 20
|
|||
var defaultEnableRelay = true
|
||||
var defaultMinPeersToPublish = 0
|
||||
var defaultEnableFilter = false
|
||||
var defaultLogLevel = "INFO"
|
||||
|
||||
func getConfig(configJSON string) (wakuConfig, error) {
|
||||
var config wakuConfig
|
||||
|
@ -93,6 +97,10 @@ func getConfig(configJSON string) (wakuConfig, error) {
|
|||
config.MinPeersToPublish = &defaultMinPeersToPublish
|
||||
}
|
||||
|
||||
if config.LogLevel == nil {
|
||||
config.LogLevel = &defaultLogLevel
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
|
@ -142,6 +150,19 @@ func NewNode(configJSON string) string {
|
|||
opts = append(opts, node.WithWakuFilter(false))
|
||||
}
|
||||
|
||||
// for go-libp2p loggers
|
||||
lvl, err := logging.LevelFromString(*config.LogLevel)
|
||||
if err != nil {
|
||||
return MakeJSONResponse(err)
|
||||
}
|
||||
logging.SetAllLoggers(lvl)
|
||||
|
||||
// go-waku logger
|
||||
err = utils.SetLogLevel(*config.LogLevel)
|
||||
if err != nil {
|
||||
return MakeJSONResponse(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
w, err := node.New(ctx, opts...)
|
||||
|
||||
|
|
Loading…
Reference in New Issue