|
@@ -123,7 +123,7 @@ func (api *PublicWhisperAPI) GenerateSymKey(name string) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// AddSymKey stores the key under the 'name' id.
|
|
// AddSymKey stores the key under the 'name' id.
|
|
|
-func (api *PublicWhisperAPI) AddSymKey(name string, key []byte) error {
|
|
|
|
|
|
|
+func (api *PublicWhisperAPI) AddSymKey(name string, key hexutil.Bytes) error {
|
|
|
if api.whisper == nil {
|
|
if api.whisper == nil {
|
|
|
return whisperOffLineErr
|
|
return whisperOffLineErr
|
|
|
}
|
|
}
|
|
@@ -151,9 +151,9 @@ func (api *PublicWhisperAPI) DeleteSymKey(name string) error {
|
|
|
|
|
|
|
|
// NewWhisperFilter creates and registers a new message filter to watch for inbound whisper messages.
|
|
// NewWhisperFilter creates and registers a new message filter to watch for inbound whisper messages.
|
|
|
// Returns the ID of the newly created Filter.
|
|
// Returns the ID of the newly created Filter.
|
|
|
-func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (uint32, error) {
|
|
|
|
|
|
|
+func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (string, error) {
|
|
|
if api.whisper == nil {
|
|
if api.whisper == nil {
|
|
|
- return 0, whisperOffLineErr
|
|
|
|
|
|
|
+ return "", whisperOffLineErr
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
filter := Filter{
|
|
filter := Filter{
|
|
@@ -168,28 +168,28 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (uint32, error) {
|
|
|
}
|
|
}
|
|
|
filter.Topics = append(filter.Topics, args.Topics...)
|
|
filter.Topics = append(filter.Topics, args.Topics...)
|
|
|
|
|
|
|
|
- if len(args.Topics) == 0 {
|
|
|
|
|
|
|
+ if len(args.Topics) == 0 && len(args.KeyName) != 0 {
|
|
|
info := "NewFilter: at least one topic must be specified"
|
|
info := "NewFilter: at least one topic must be specified"
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
- return 0, errors.New(info)
|
|
|
|
|
|
|
+ return "", errors.New(info)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if len(args.KeyName) != 0 && len(filter.KeySym) == 0 {
|
|
if len(args.KeyName) != 0 && len(filter.KeySym) == 0 {
|
|
|
info := "NewFilter: key was not found by name: " + args.KeyName
|
|
info := "NewFilter: key was not found by name: " + args.KeyName
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
- return 0, errors.New(info)
|
|
|
|
|
|
|
+ return "", errors.New(info)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if len(args.To) == 0 && len(filter.KeySym) == 0 {
|
|
if len(args.To) == 0 && len(filter.KeySym) == 0 {
|
|
|
info := "NewFilter: filter must contain either symmetric or asymmetric key"
|
|
info := "NewFilter: filter must contain either symmetric or asymmetric key"
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
- return 0, errors.New(info)
|
|
|
|
|
|
|
+ return "", errors.New(info)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if len(args.To) != 0 && len(filter.KeySym) != 0 {
|
|
if len(args.To) != 0 && len(filter.KeySym) != 0 {
|
|
|
info := "NewFilter: filter must not contain both symmetric and asymmetric key"
|
|
info := "NewFilter: filter must not contain both symmetric and asymmetric key"
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
- return 0, errors.New(info)
|
|
|
|
|
|
|
+ return "", errors.New(info)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if len(args.To) > 0 {
|
|
if len(args.To) > 0 {
|
|
@@ -197,13 +197,13 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (uint32, error) {
|
|
|
if !ValidatePublicKey(dst) {
|
|
if !ValidatePublicKey(dst) {
|
|
|
info := "NewFilter: Invalid 'To' address"
|
|
info := "NewFilter: Invalid 'To' address"
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
- return 0, errors.New(info)
|
|
|
|
|
|
|
+ return "", errors.New(info)
|
|
|
}
|
|
}
|
|
|
filter.KeyAsym = api.whisper.GetIdentity(string(args.To))
|
|
filter.KeyAsym = api.whisper.GetIdentity(string(args.To))
|
|
|
if filter.KeyAsym == nil {
|
|
if filter.KeyAsym == nil {
|
|
|
info := "NewFilter: non-existent identity provided"
|
|
info := "NewFilter: non-existent identity provided"
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
- return 0, errors.New(info)
|
|
|
|
|
|
|
+ return "", errors.New(info)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -211,21 +211,20 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (uint32, error) {
|
|
|
if !ValidatePublicKey(filter.Src) {
|
|
if !ValidatePublicKey(filter.Src) {
|
|
|
info := "NewFilter: Invalid 'From' address"
|
|
info := "NewFilter: Invalid 'From' address"
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
- return 0, errors.New(info)
|
|
|
|
|
|
|
+ return "", errors.New(info)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- id := api.whisper.Watch(&filter)
|
|
|
|
|
- return id, nil
|
|
|
|
|
|
|
+ return api.whisper.Watch(&filter)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// UninstallFilter disables and removes an existing filter.
|
|
// UninstallFilter disables and removes an existing filter.
|
|
|
-func (api *PublicWhisperAPI) UninstallFilter(filterId uint32) {
|
|
|
|
|
|
|
+func (api *PublicWhisperAPI) UninstallFilter(filterId string) {
|
|
|
api.whisper.Unwatch(filterId)
|
|
api.whisper.Unwatch(filterId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GetFilterChanges retrieves all the new messages matched by a filter since the last retrieval.
|
|
// GetFilterChanges retrieves all the new messages matched by a filter since the last retrieval.
|
|
|
-func (api *PublicWhisperAPI) GetFilterChanges(filterId uint32) []WhisperMessage {
|
|
|
|
|
|
|
+func (api *PublicWhisperAPI) GetFilterChanges(filterId string) []*WhisperMessage {
|
|
|
f := api.whisper.GetFilter(filterId)
|
|
f := api.whisper.GetFilter(filterId)
|
|
|
if f != nil {
|
|
if f != nil {
|
|
|
newMail := f.Retrieve()
|
|
newMail := f.Retrieve()
|
|
@@ -235,14 +234,14 @@ func (api *PublicWhisperAPI) GetFilterChanges(filterId uint32) []WhisperMessage
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GetMessages retrieves all the known messages that match a specific filter.
|
|
// GetMessages retrieves all the known messages that match a specific filter.
|
|
|
-func (api *PublicWhisperAPI) GetMessages(filterId uint32) []WhisperMessage {
|
|
|
|
|
|
|
+func (api *PublicWhisperAPI) GetMessages(filterId string) []*WhisperMessage {
|
|
|
all := api.whisper.Messages(filterId)
|
|
all := api.whisper.Messages(filterId)
|
|
|
return toWhisperMessages(all)
|
|
return toWhisperMessages(all)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// toWhisperMessages converts a Whisper message to a RPC whisper message.
|
|
// toWhisperMessages converts a Whisper message to a RPC whisper message.
|
|
|
-func toWhisperMessages(messages []*ReceivedMessage) []WhisperMessage {
|
|
|
|
|
- msgs := make([]WhisperMessage, len(messages))
|
|
|
|
|
|
|
+func toWhisperMessages(messages []*ReceivedMessage) []*WhisperMessage {
|
|
|
|
|
+ msgs := make([]*WhisperMessage, len(messages))
|
|
|
for i, msg := range messages {
|
|
for i, msg := range messages {
|
|
|
msgs[i] = NewWhisperMessage(msg)
|
|
msgs[i] = NewWhisperMessage(msg)
|
|
|
}
|
|
}
|
|
@@ -282,8 +281,8 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
filter := api.whisper.GetFilter(args.FilterID)
|
|
filter := api.whisper.GetFilter(args.FilterID)
|
|
|
- if filter == nil && args.FilterID > 0 {
|
|
|
|
|
- info := fmt.Sprintf("Post: wrong filter id %d", args.FilterID)
|
|
|
|
|
|
|
+ if filter == nil && len(args.FilterID) > 0 {
|
|
|
|
|
+ info := fmt.Sprintf("Post: wrong filter id %s", args.FilterID)
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
return errors.New(info)
|
|
return errors.New(info)
|
|
|
}
|
|
}
|
|
@@ -299,7 +298,7 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
|
|
|
if (params.Topic == TopicType{}) {
|
|
if (params.Topic == TopicType{}) {
|
|
|
sz := len(filter.Topics)
|
|
sz := len(filter.Topics)
|
|
|
if sz < 1 {
|
|
if sz < 1 {
|
|
|
- info := fmt.Sprintf("Post: no topics in filter # %d", args.FilterID)
|
|
|
|
|
|
|
+ info := fmt.Sprintf("Post: no topics in filter # %s", args.FilterID)
|
|
|
glog.V(logger.Error).Infof(info)
|
|
glog.V(logger.Error).Infof(info)
|
|
|
return errors.New(info)
|
|
return errors.New(info)
|
|
|
} else if sz == 1 {
|
|
} else if sz == 1 {
|
|
@@ -374,17 +373,17 @@ type PostArgs struct {
|
|
|
Payload hexutil.Bytes `json:"payload"`
|
|
Payload hexutil.Bytes `json:"payload"`
|
|
|
WorkTime uint32 `json:"worktime"`
|
|
WorkTime uint32 `json:"worktime"`
|
|
|
PoW float64 `json:"pow"`
|
|
PoW float64 `json:"pow"`
|
|
|
- FilterID uint32 `json:"filterID"`
|
|
|
|
|
|
|
+ FilterID string `json:"filterID"`
|
|
|
PeerID hexutil.Bytes `json:"peerID"`
|
|
PeerID hexutil.Bytes `json:"peerID"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type WhisperFilterArgs struct {
|
|
type WhisperFilterArgs struct {
|
|
|
- To string
|
|
|
|
|
- From string
|
|
|
|
|
- KeyName string
|
|
|
|
|
- PoW float64
|
|
|
|
|
- Topics []TopicType
|
|
|
|
|
- AcceptP2P bool
|
|
|
|
|
|
|
+ To string `json:"to"`
|
|
|
|
|
+ From string `json:"from"`
|
|
|
|
|
+ KeyName string `json:"keyname"`
|
|
|
|
|
+ PoW float64 `json:"pow"`
|
|
|
|
|
+ Topics []TopicType `json:"topics"`
|
|
|
|
|
+ AcceptP2P bool `json:"p2p"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON implements the json.Unmarshaler interface, invoked to convert a
|
|
// UnmarshalJSON implements the json.Unmarshaler interface, invoked to convert a
|
|
@@ -397,7 +396,7 @@ func (args *WhisperFilterArgs) UnmarshalJSON(b []byte) (err error) {
|
|
|
KeyName string `json:"keyname"`
|
|
KeyName string `json:"keyname"`
|
|
|
PoW float64 `json:"pow"`
|
|
PoW float64 `json:"pow"`
|
|
|
Topics []interface{} `json:"topics"`
|
|
Topics []interface{} `json:"topics"`
|
|
|
- AcceptP2P bool `json:"acceptP2P"`
|
|
|
|
|
|
|
+ AcceptP2P bool `json:"p2p"`
|
|
|
}
|
|
}
|
|
|
if err := json.Unmarshal(b, &obj); err != nil {
|
|
if err := json.Unmarshal(b, &obj); err != nil {
|
|
|
return err
|
|
return err
|
|
@@ -438,6 +437,7 @@ func (args *WhisperFilterArgs) UnmarshalJSON(b []byte) (err error) {
|
|
|
|
|
|
|
|
// WhisperMessage is the RPC representation of a whisper message.
|
|
// WhisperMessage is the RPC representation of a whisper message.
|
|
|
type WhisperMessage struct {
|
|
type WhisperMessage struct {
|
|
|
|
|
+ Topic string `json:"topic"`
|
|
|
Payload string `json:"payload"`
|
|
Payload string `json:"payload"`
|
|
|
Padding string `json:"padding"`
|
|
Padding string `json:"padding"`
|
|
|
From string `json:"from"`
|
|
From string `json:"from"`
|
|
@@ -449,15 +449,22 @@ type WhisperMessage struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// NewWhisperMessage converts an internal message into an API version.
|
|
// NewWhisperMessage converts an internal message into an API version.
|
|
|
-func NewWhisperMessage(message *ReceivedMessage) WhisperMessage {
|
|
|
|
|
- return WhisperMessage{
|
|
|
|
|
|
|
+func NewWhisperMessage(message *ReceivedMessage) *WhisperMessage {
|
|
|
|
|
+ msg := WhisperMessage{
|
|
|
|
|
+ Topic: common.ToHex(message.Topic[:]),
|
|
|
Payload: common.ToHex(message.Payload),
|
|
Payload: common.ToHex(message.Payload),
|
|
|
Padding: common.ToHex(message.Padding),
|
|
Padding: common.ToHex(message.Padding),
|
|
|
- From: common.ToHex(crypto.FromECDSAPub(message.SigToPubKey())),
|
|
|
|
|
- To: common.ToHex(crypto.FromECDSAPub(message.Dst)),
|
|
|
|
|
Sent: message.Sent,
|
|
Sent: message.Sent,
|
|
|
TTL: message.TTL,
|
|
TTL: message.TTL,
|
|
|
PoW: message.PoW,
|
|
PoW: message.PoW,
|
|
|
Hash: common.ToHex(message.EnvelopeHash.Bytes()),
|
|
Hash: common.ToHex(message.EnvelopeHash.Bytes()),
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if message.Dst != nil {
|
|
|
|
|
+ msg.To = common.ToHex(crypto.FromECDSAPub(message.Dst))
|
|
|
|
|
+ }
|
|
|
|
|
+ if isMessageSigned(message.Raw[0]) {
|
|
|
|
|
+ msg.From = common.ToHex(crypto.FromECDSAPub(message.SigToPubKey()))
|
|
|
|
|
+ }
|
|
|
|
|
+ return &msg
|
|
|
}
|
|
}
|