From 9137257638bb5b9f6d7e336d0a2a24d65838a2ac Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 29 Dec 2022 14:16:19 +0800 Subject: [PATCH] synchronize display name (#2989) --- api/utils.go | 4 +++- eth-node/crypto/crypto.go | 6 ++++-- eth-node/crypto/gethcrypto.go | 2 +- go.mod | 2 +- mobile/status.go | 11 +++++++++-- peers/topicpool.go | 16 ++++++++-------- protocol/messenger.go | 3 +-- protocol/messenger_handler.go | 16 ++++++++++++++++ protocol/messenger_response.go | 4 ++++ rpc/doc.go | 1 - rpc/route.go | 8 +++++--- services/rpcfilters/logs_cache.go | 4 +++- services/wallet/transfer/database.go | 2 +- signal/signals.go | 6 ++++-- waku/v0/peer_test.go | 2 +- waku/v1/peer_test.go | 2 +- waku/waku_version_test.go | 8 ++++---- 17 files changed, 66 insertions(+), 31 deletions(-) diff --git a/api/utils.go b/api/utils.go index f15e28db8..f1449fc05 100644 --- a/api/utils.go +++ b/api/utils.go @@ -22,7 +22,9 @@ func RunAsync(f func() error) <-chan error { // HashMessage calculates the hash of a message to be safely signed by the keycard // The hash is calulcated as -// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// // This gives context to the signed message and prevents signing of transactions. func HashMessage(message string) ([]byte, error) { buf := bytes.NewBufferString("\x19Ethereum Signed Message:\n") diff --git a/eth-node/crypto/crypto.go b/eth-node/crypto/crypto.go index 33cc6036b..df8830169 100644 --- a/eth-node/crypto/crypto.go +++ b/eth-node/crypto/crypto.go @@ -202,7 +202,8 @@ func generateSecureRandomData(length int) ([]byte, error) { // safely used to calculate a signature from. // // The hash is calulcated as -// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). // // This gives context to the signed message and prevents signing of transactions. func TextHash(data []byte) []byte { @@ -214,7 +215,8 @@ func TextHash(data []byte) []byte { // safely used to calculate a signature from. // // The hash is calulcated as -// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). // // This gives context to the signed message and prevents signing of transactions. func TextAndHash(data []byte) ([]byte, string) { diff --git a/eth-node/crypto/gethcrypto.go b/eth-node/crypto/gethcrypto.go index d453a5b4a..80070f06e 100644 --- a/eth-node/crypto/gethcrypto.go +++ b/eth-node/crypto/gethcrypto.go @@ -37,7 +37,7 @@ import ( "github.com/status-im/status-go/eth-node/types" ) -//SignatureLength indicates the byte length required to carry a signature with recovery id. +// SignatureLength indicates the byte length required to carry a signature with recovery id. const SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id // RecoveryIDOffset points to the byte offset within the signature that contains the recovery id. diff --git a/go.mod b/go.mod index 9be75e830..7e6fe0ff2 100644 --- a/go.mod +++ b/go.mod @@ -68,7 +68,7 @@ require ( go.uber.org/zap v1.23.0 golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb - google.golang.org/protobuf v1.28.1 // indirect + google.golang.org/protobuf v1.28.1 gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 diff --git a/mobile/status.go b/mobile/status.go index 23fc03939..8995de100 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -442,6 +442,7 @@ func SignMessage(rpcParams string) string { // SignTypedData unmarshall data into TypedData, validate it and signs with selected account, // if password matches selected account. +// //export SignTypedData func SignTypedData(data, address, password string) string { var typed typeddata.TypedData @@ -457,6 +458,7 @@ func SignTypedData(data, address, password string) string { } // HashTypedData unmarshalls data into TypedData, validates it and hashes it. +// //export HashTypedData func HashTypedData(data string) string { var typed typeddata.TypedData @@ -473,6 +475,7 @@ func HashTypedData(data string) string { // SignTypedDataV4 unmarshall data into TypedData, validate it and signs with selected account, // if password matches selected account. +// //export SignTypedDataV4 func SignTypedDataV4(data, address, password string) string { var typed apitypes.TypedData @@ -485,6 +488,7 @@ func SignTypedDataV4(data, address, password string) string { } // HashTypedDataV4 unmarshalls data into TypedData, validates it and hashes it. +// //export HashTypedDataV4 func HashTypedDataV4(data string) string { var typed apitypes.TypedData @@ -586,7 +590,9 @@ func HashTransaction(txArgsJSON string) string { // HashMessage calculates the hash of a message to be safely signed by the keycard // The hash is calulcated as -// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// // This gives context to the signed message and prevents signing of transactions. func HashMessage(message string) string { hash, err := api.HashMessage(message) @@ -609,7 +615,7 @@ func StopCPUProfiling() string { //nolint: deadcode return makeJSONResponse(err) } -//WriteHeapProfile starts pprof for heap +// WriteHeapProfile starts pprof for heap func WriteHeapProfile(dataDir string) string { //nolint: deadcode err := profiling.WriteHeapFile(dataDir) return makeJSONResponse(err) @@ -675,6 +681,7 @@ func SetSignalEventCallback(cb unsafe.Pointer) { } // ExportNodeLogs reads current node log and returns content to a caller. +// //export ExportNodeLogs func ExportNodeLogs() string { node := statusBackend.StatusNode() diff --git a/peers/topicpool.go b/peers/topicpool.go index 74042645f..9818af8e6 100644 --- a/peers/topicpool.go +++ b/peers/topicpool.go @@ -300,12 +300,12 @@ func (t *TopicPool) limitFastMode(timeout time.Duration) chan struct{} { } // ConfirmAdded called when peer was added by p2p Server. -// 1. Skip a peer if it not in our peer table -// 2. Add a peer to a cache. -// 3. Disconnect a peer if it was connected after we reached max limit of peers. -// (we can't know in advance if peer will be connected, thats why we allow +// 1. Skip a peer if it not in our peer table +// 2. Add a peer to a cache. +// 3. Disconnect a peer if it was connected after we reached max limit of peers. +// (we can't know in advance if peer will be connected, thats why we allow // to overflow for short duration) -// 4. Switch search to slow mode if it is running. +// 4. Switch search to slow mode if it is running. func (t *TopicPool) ConfirmAdded(server *p2p.Server, nodeID enode.ID) { t.mu.Lock() defer t.mu.Unlock() @@ -475,9 +475,9 @@ func (t *TopicPool) handleFoundPeers(server *p2p.Server, found <-chan *discv5.No // processFoundNode called when node is discovered by kademlia search query // 2 important conditions -// 1. every time when node is processed we need to update discoveredTime. -// peer will be considered as valid later only if it was discovered < 60m ago -// 2. if peer is connected or if max limit is reached we are not a adding peer to p2p server +// 1. every time when node is processed we need to update discoveredTime. +// peer will be considered as valid later only if it was discovered < 60m ago +// 2. if peer is connected or if max limit is reached we are not a adding peer to p2p server func (t *TopicPool) processFoundNode(server *p2p.Server, node *discv5.Node) error { t.mu.Lock() defer t.mu.Unlock() diff --git a/protocol/messenger.go b/protocol/messenger.go index 9c4001903..54cc8818d 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -3708,13 +3708,12 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte m.outputToCSV(msg.TransportMessage.Timestamp, msg.ID, senderID, filter.Topic, filter.ChatID, msg.Type, ss) logger.Debug("Handling SyncSetting", zap.Any("message", ss)) - settingField, err := m.extractSyncSetting(&ss) + err := m.handleSyncSetting(messageState, &ss) if err != nil { logger.Warn("failed to handle SyncSetting", zap.Error(err)) allMessagesProcessed = false continue } - messageState.Response.Settings = append(messageState.Response.Settings, settingField) case protobuf.RequestAddressForTransaction: command := msg.ParsedMessage.Interface().(protobuf.RequestAddressForTransaction) diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index 6e2794bf3..4180af5ec 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -1718,6 +1718,22 @@ func (m *Messenger) HandleRequestAddressForTransaction(messageState *ReceivedMes return m.handleCommandMessage(messageState, message) } +func (m *Messenger) handleSyncSetting(messageState *ReceivedMessageState, message *protobuf.SyncSetting) error { + settingField, err := m.extractSyncSetting(message) + if err != nil { + return err + } + if message.GetType() == protobuf.SyncSetting_DISPLAY_NAME { + m.account.Name = message.GetValueString() + err = m.multiAccounts.SaveAccount(*m.account) + if err != nil { + return err + } + } + messageState.Response.AddSetting(settingField) + return nil +} + func (m *Messenger) HandleRequestTransaction(messageState *ReceivedMessageState, command protobuf.RequestTransaction) error { err := ValidateReceivedRequestTransaction(&command, messageState.CurrentMessageState.WhisperTimestamp) if err != nil { diff --git a/protocol/messenger_response.go b/protocol/messenger_response.go index c5d55f2be..e00640d5d 100644 --- a/protocol/messenger_response.go +++ b/protocol/messenger_response.go @@ -308,6 +308,10 @@ func (r *MessengerResponse) AddCommunitySettings(c *communities.CommunitySetting r.communitiesSettings[c.CommunityID] = c } +func (r *MessengerResponse) AddSetting(s *settings.SyncSettingField) { + r.Settings = append(r.Settings, s) +} + func (r *MessengerResponse) AddBookmark(bookmark *browsers.Bookmark) { r.Bookmarks = append(r.Bookmarks, bookmark) } diff --git a/rpc/doc.go b/rpc/doc.go index fbc80407b..ce3fbc324 100644 --- a/rpc/doc.go +++ b/rpc/doc.go @@ -15,7 +15,6 @@ Routing rules are following: List of methods to be routed is currently available here: https://docs.google.com/spreadsheets/d/1N1nuzVN5tXoDmzkBLeC9_mwIlVH8DGF7YD2XwxA8BAE/edit#gid=0 Note, upon creation of a new client, it ok to be offline - client will keep trying to reconnect in background. - */ package rpc diff --git a/rpc/route.go b/rpc/route.go index 9745fcc12..4aa7d3cf1 100644 --- a/rpc/route.go +++ b/rpc/route.go @@ -59,9 +59,11 @@ func BlockedMethods() []string { // the upstream node; the rest is considered to be routed to // the local node. // A list of supported methods: -// curl --include \ -// --header "Content-Type: application/json" \ -// --header "Accept: application/json" 'https://api.infura.io/v1/jsonrpc/ropsten/methods' +// +// curl --include \ +// --header "Content-Type: application/json" \ +// --header "Accept: application/json" 'https://api.infura.io/v1/jsonrpc/ropsten/methods' +// // Although it's tempting to only list methods coming to the local node as there're fewer of them // but it's deceptive: we want to ensure that only known requests leave our zone of responsibility. // Also, we want new requests in newer Geth versions not to be accidentally routed to the upstream. diff --git a/services/rpcfilters/logs_cache.go b/services/rpcfilters/logs_cache.go index ce6662fdc..aba9a6d19 100644 --- a/services/rpcfilters/logs_cache.go +++ b/services/rpcfilters/logs_cache.go @@ -85,7 +85,9 @@ func checkLogsAreInOrder(records []cacheRecord) error { // merge merges received records into old slice starting at provided position, example: // [1, 2, 3] -// [2, 3, 4] +// +// [2, 3, 4] +// // [1, 2, 3, 4] // if hash doesn't match previously received hash - such block was removed due to reorg // logs that were a part of that block will be returned with Removed set to true diff --git a/services/wallet/transfer/database.go b/services/wallet/transfer/database.go index bac4cb9c5..bf56cd3f2 100644 --- a/services/wallet/transfer/database.go +++ b/services/wallet/transfer/database.go @@ -463,7 +463,7 @@ func updateOrInsertTransfers(chainID uint64, creator statementCreator, transfers return nil } -//markBlocksAsLoaded(tx, address, chainID, blocks) +// markBlocksAsLoaded(tx, address, chainID, blocks) func markBlocksAsLoaded(chainID uint64, creator statementCreator, address common.Address, blocks []*big.Int) error { update, err := creator.Prepare("UPDATE blocks SET loaded=? WHERE address=? AND blk_number=? AND network_id=?") if err != nil { diff --git a/signal/signals.go b/signal/signals.go index 8073a6331..81aed7ab4 100644 --- a/signal/signals.go +++ b/signal/signals.go @@ -87,16 +87,18 @@ func TriggerDefaultNodeNotificationHandler(jsonEvent string) { logger.Trace("Notification received", "event", jsonEvent) } +// nolint: golint +// //export NotifyNode -//nolint: golint func NotifyNode(jsonEvent *C.char) { notificationHandlerMutex.RLock() defer notificationHandlerMutex.RUnlock() notificationHandler(C.GoString(jsonEvent)) } +// nolint: golint +// //export TriggerTestSignal -//nolint: golint func TriggerTestSignal() { str := C.CString(`{"answer": 42}`) C.StatusServiceSignalEvent(str) diff --git a/waku/v0/peer_test.go b/waku/v0/peer_test.go index c3e68cfc2..3a6972e1b 100644 --- a/waku/v0/peer_test.go +++ b/waku/v0/peer_test.go @@ -44,7 +44,7 @@ func initSingleTest() { var sharedTopic = common.TopicType{0xF, 0x1, 0x2, 0} var wrongTopic = common.TopicType{0, 0, 0, 0} -//two generic waku node handshake. one don't send light flag +// two generic waku node handshake. one don't send light flag func TestTopicOrBloomMatch(t *testing.T) { p := Peer{} p.setTopicInterest([]common.TopicType{sharedTopic}) diff --git a/waku/v1/peer_test.go b/waku/v1/peer_test.go index 0a9f8c74b..3c5cd770d 100644 --- a/waku/v1/peer_test.go +++ b/waku/v1/peer_test.go @@ -44,7 +44,7 @@ func initSingleTest() { var sharedTopic = common.TopicType{0xF, 0x1, 0x2, 0} var wrongTopic = common.TopicType{0, 0, 0, 0} -//two generic waku node handshake. one don't send light flag +// two generic waku node handshake. one don't send light flag func TestTopicOrBloomMatch(t *testing.T) { p := Peer{} p.setTopicInterest([]common.TopicType{sharedTopic}) diff --git a/waku/waku_version_test.go b/waku/waku_version_test.go index 3df076aa9..423bb1e81 100644 --- a/waku/waku_version_test.go +++ b/waku/waku_version_test.go @@ -547,7 +547,7 @@ func (s *WakuTestSuite) TestMailserverCompletionEvent() { } } -//two generic waku node handshake +// two generic waku node handshake func (s *WakuTestSuite) TestPeerHandshakeWithTwoFullNode() { rw1, rw2 := p2p.MsgPipe() defer func() { handleError(s.T(), rw1.Close()) }() @@ -571,7 +571,7 @@ func (s *WakuTestSuite) TestPeerHandshakeWithTwoFullNode() { s.Require().Equal(pow, p2.PoWRequirement()) } -//two generic waku node handshake. one don't send light flag +// two generic waku node handshake. one don't send light flag func (s *WakuTestSuite) TestHandshakeWithOldVersionWithoutLightModeFlag() { rw1, rw2 := p2p.MsgPipe() defer func() { handleError(s.T(), rw1.Close()) }() @@ -591,7 +591,7 @@ func (s *WakuTestSuite) TestHandshakeWithOldVersionWithoutLightModeFlag() { s.Require().NoError(err) } -//two light nodes handshake. restriction enable +// two light nodes handshake. restriction enable func (s *WakuTestSuite) TestTwoLightPeerHandshakeRestrictionOff() { rw1, rw2 := p2p.MsgPipe() defer func() { handleError(s.T(), rw1.Close()) }() @@ -613,7 +613,7 @@ func (s *WakuTestSuite) TestTwoLightPeerHandshakeRestrictionOff() { s.Require().NoError(p2.Start()) } -//two light nodes handshake. restriction enabled +// two light nodes handshake. restriction enabled func (s *WakuTestSuite) TestTwoLightPeerHandshakeError() { rw1, rw2 := p2p.MsgPipe() defer func() { handleError(s.T(), rw1.Close()) }()