doc.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2016 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. /*
  17. Package whisperv5 implements the Whisper protocol (version 5).
  18. Whisper combines aspects of both DHTs and datagram messaging systems (e.g. UDP).
  19. As such it may be likened and compared to both, not dissimilar to the
  20. matter/energy duality (apologies to physicists for the blatant abuse of a
  21. fundamental and beautiful natural principle).
  22. Whisper is a pure identity-based messaging system. Whisper provides a low-level
  23. (non-application-specific) but easily-accessible API without being based upon
  24. or prejudiced by the low-level hardware attributes and characteristics,
  25. particularly the notion of singular endpoints.
  26. */
  27. package whisperv5
  28. import (
  29. "fmt"
  30. "time"
  31. )
  32. const (
  33. EnvelopeVersion = uint64(0)
  34. ProtocolVersion = uint64(5)
  35. ProtocolVersionStr = "5.0"
  36. ProtocolName = "shh"
  37. statusCode = 0 // used by whisper protocol
  38. messagesCode = 1 // normal whisper message
  39. p2pCode = 2 // peer-to-peer message (to be consumed by the peer, but not forwarded any further)
  40. p2pRequestCode = 3 // peer-to-peer message, used by Dapp protocol
  41. NumberOfMessageCodes = 64
  42. paddingMask = byte(3)
  43. signatureFlag = byte(4)
  44. TopicLength = 4
  45. signatureLength = 65
  46. aesKeyLength = 32
  47. AESNonceLength = 12
  48. keyIdSize = 32
  49. MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message.
  50. DefaultMaxMessageSize = uint32(1024 * 1024)
  51. DefaultMinimumPoW = 0.2
  52. padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol (must not exceed 2^24)
  53. messageQueueLimit = 1024
  54. expirationCycle = time.Second
  55. transmissionCycle = 300 * time.Millisecond
  56. DefaultTTL = 50 // seconds
  57. SynchAllowance = 10 // seconds
  58. )
  59. type unknownVersionError uint64
  60. func (e unknownVersionError) Error() string {
  61. return fmt.Sprintf("invalid envelope version %d", uint64(e))
  62. }
  63. // MailServer represents a mail server, capable of
  64. // archiving the old messages for subsequent delivery
  65. // to the peers. Any implementation must ensure that both
  66. // functions are thread-safe. Also, they must return ASAP.
  67. // DeliverMail should use directMessagesCode for delivery,
  68. // in order to bypass the expiry checks.
  69. type MailServer interface {
  70. Archive(env *Envelope)
  71. DeliverMail(whisperPeer *Peer, request *Envelope)
  72. }