parent
465afd0131
commit
170ae0d455
|
@ -23,8 +23,7 @@ const (
|
||||||
|
|
||||||
// Account handling
|
// Account handling
|
||||||
|
|
||||||
func handleReceiveAccount(hs HandlerServer, pr PayloadReceiver) http.HandlerFunc {
|
func handleReceiveAccount(logger *zap.Logger, pr PayloadReceiver) http.HandlerFunc {
|
||||||
logger := hs.GetLogger()
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingAccount})
|
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingAccount})
|
||||||
payload, err := io.ReadAll(r.Body)
|
payload, err := io.ReadAll(r.Body)
|
||||||
|
@ -47,8 +46,7 @@ func handleReceiveAccount(hs HandlerServer, pr PayloadReceiver) http.HandlerFunc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSendAccount(hs HandlerServer, pm PayloadMounter) http.HandlerFunc {
|
func handleSendAccount(logger *zap.Logger, pm PayloadMounter) http.HandlerFunc {
|
||||||
logger := hs.GetLogger()
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingAccount})
|
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingAccount})
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
@ -75,8 +73,7 @@ func handleSendAccount(hs HandlerServer, pm PayloadMounter) http.HandlerFunc {
|
||||||
|
|
||||||
// Device sync handling
|
// Device sync handling
|
||||||
|
|
||||||
func handleParingSyncDeviceReceive(hs HandlerServer, pr PayloadReceiver) http.HandlerFunc {
|
func handleParingSyncDeviceReceive(logger *zap.Logger, pr PayloadReceiver) http.HandlerFunc {
|
||||||
logger := hs.GetLogger()
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionSyncDevice})
|
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionSyncDevice})
|
||||||
payload, err := io.ReadAll(r.Body)
|
payload, err := io.ReadAll(r.Body)
|
||||||
|
@ -99,8 +96,7 @@ func handleParingSyncDeviceReceive(hs HandlerServer, pr PayloadReceiver) http.Ha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePairingSyncDeviceSend(hs HandlerServer, pm PayloadMounter) http.HandlerFunc {
|
func handlePairingSyncDeviceSend(logger *zap.Logger, pm PayloadMounter) http.HandlerFunc {
|
||||||
logger := hs.GetLogger()
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionSyncDevice})
|
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionSyncDevice})
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
@ -129,8 +125,7 @@ func handlePairingSyncDeviceSend(hs HandlerServer, pm PayloadMounter) http.Handl
|
||||||
|
|
||||||
// Installation data handling
|
// Installation data handling
|
||||||
|
|
||||||
func handleReceiveInstallation(hs HandlerServer, pmr PayloadMounterReceiver) http.HandlerFunc {
|
func handleReceiveInstallation(logger *zap.Logger, pmr PayloadMounterReceiver) http.HandlerFunc {
|
||||||
logger := hs.GetLogger()
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingInstallation})
|
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingInstallation})
|
||||||
payload, err := io.ReadAll(r.Body)
|
payload, err := io.ReadAll(r.Body)
|
||||||
|
@ -153,8 +148,7 @@ func handleReceiveInstallation(hs HandlerServer, pmr PayloadMounterReceiver) htt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSendInstallation(hs HandlerServer, pmr PayloadMounterReceiver) http.HandlerFunc {
|
func handleSendInstallation(logger *zap.Logger, pmr PayloadMounterReceiver) http.HandlerFunc {
|
||||||
logger := hs.GetLogger()
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingInstallation})
|
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingInstallation})
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package pairing
|
package pairing
|
||||||
|
|
||||||
import (
|
|
||||||
"go.uber.org/zap"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PayloadMounterReceiver represents a struct that can:
|
// PayloadMounterReceiver represents a struct that can:
|
||||||
// - mount payload data from a PayloadRepository or a PayloadLoader into memory (PayloadMounter.Mount)
|
// - mount payload data from a PayloadRepository or a PayloadLoader into memory (PayloadMounter.Mount)
|
||||||
// - prepare data to be sent encrypted (PayloadMounter.ToSend) via some transport
|
// - prepare data to be sent encrypted (PayloadMounter.ToSend) via some transport
|
||||||
|
@ -25,14 +21,6 @@ type PayloadLocker interface {
|
||||||
LockPayload()
|
LockPayload()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO if this interface only gets a logger, then maybe remove the interface and change consuming function params
|
|
||||||
// to accept a *zap.logger
|
|
||||||
// https://github.com/status-im/status-go/issues/3370
|
|
||||||
|
|
||||||
type HandlerServer interface {
|
|
||||||
GetLogger() *zap.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProtobufMarshaller interface {
|
type ProtobufMarshaller interface {
|
||||||
MarshalProtobuf() ([]byte, error)
|
MarshalProtobuf() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,13 +142,13 @@ func NewSenderServer(backend *api.GethStatusBackend, config *SenderServerConfig)
|
||||||
func (s *SenderServer) startSendingData() error {
|
func (s *SenderServer) startSendingData() error {
|
||||||
s.SetHandlers(server.HandlerPatternMap{
|
s.SetHandlers(server.HandlerPatternMap{
|
||||||
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
||||||
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(s, s.accountMounter)),
|
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(s.GetLogger(), s.accountMounter)),
|
||||||
pairingSendSyncDevice: middlewareChallenge(s.challengeGiver, handlePairingSyncDeviceSend(s, s.rawMessageMounter)),
|
pairingSendSyncDevice: middlewareChallenge(s.challengeGiver, handlePairingSyncDeviceSend(s.GetLogger(), s.rawMessageMounter)),
|
||||||
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
||||||
// the other handlers.
|
// the other handlers.
|
||||||
// https://github.com/status-im/status-go/issues/3304
|
// https://github.com/status-im/status-go/issues/3304
|
||||||
// receive installation data from receiver
|
// receive installation data from receiver
|
||||||
pairingReceiveInstallation: middlewareChallenge(s.challengeGiver, handleReceiveInstallation(s, s.installationMounter)),
|
pairingReceiveInstallation: middlewareChallenge(s.challengeGiver, handleReceiveInstallation(s.GetLogger(), s.installationMounter)),
|
||||||
})
|
})
|
||||||
return s.Start()
|
return s.Start()
|
||||||
}
|
}
|
||||||
|
@ -237,13 +237,13 @@ func NewReceiverServer(backend *api.GethStatusBackend, config *ReceiverServerCon
|
||||||
func (s *ReceiverServer) startReceivingData() error {
|
func (s *ReceiverServer) startReceivingData() error {
|
||||||
s.SetHandlers(server.HandlerPatternMap{
|
s.SetHandlers(server.HandlerPatternMap{
|
||||||
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
||||||
pairingReceiveAccount: handleReceiveAccount(s, s.accountReceiver),
|
pairingReceiveAccount: handleReceiveAccount(s.GetLogger(), s.accountReceiver),
|
||||||
pairingReceiveSyncDevice: handleParingSyncDeviceReceive(s, s.rawMessageReceiver),
|
pairingReceiveSyncDevice: handleParingSyncDeviceReceive(s.GetLogger(), s.rawMessageReceiver),
|
||||||
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
||||||
// the other handlers.
|
// the other handlers.
|
||||||
// https://github.com/status-im/status-go/issues/3304
|
// https://github.com/status-im/status-go/issues/3304
|
||||||
// send installation data back to sender
|
// send installation data back to sender
|
||||||
pairingSendInstallation: middlewareChallenge(s.challengeGiver, handleSendInstallation(s, s.installationReceiver)),
|
pairingSendInstallation: middlewareChallenge(s.challengeGiver, handleSendInstallation(s.GetLogger(), s.installationReceiver)),
|
||||||
})
|
})
|
||||||
return s.Start()
|
return s.Start()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue