doc.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 whisper implements the Whisper protocol (version 6).
  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. // Contains the Whisper protocol constant definitions
  28. package whisperv6
  29. import (
  30. "fmt"
  31. "time"
  32. )
  33. // Whisper protocol parameters
  34. const (
  35. ProtocolVersion = uint64(6) // Protocol version number
  36. ProtocolVersionStr = "6.0" // The same, as a string
  37. ProtocolName = "shh" // Nickname of the protocol in geth
  38. // whisper protocol message codes, according to EIP-627
  39. statusCode = 0 // used by whisper protocol
  40. messagesCode = 1 // normal whisper message
  41. powRequirementCode = 2 // PoW requirement
  42. bloomFilterExCode = 3 // bloom filter exchange
  43. p2pRequestCode = 126 // peer-to-peer message, used by Dapp protocol
  44. p2pMessageCode = 127 // peer-to-peer message (to be consumed by the peer, but not forwarded any further)
  45. NumberOfMessageCodes = 128
  46. SizeMask = byte(3) // mask used to extract the size of payload size field from the flags
  47. signatureFlag = byte(4)
  48. TopicLength = 4 // in bytes
  49. signatureLength = 65 // in bytes
  50. aesKeyLength = 32 // in bytes
  51. aesNonceLength = 12 // in bytes; for more info please see cipher.gcmStandardNonceSize & aesgcm.NonceSize()
  52. keyIDSize = 32 // in bytes
  53. BloomFilterSize = 64 // in bytes
  54. flagsLength = 1
  55. EnvelopeHeaderLength = 20
  56. MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message.
  57. DefaultMaxMessageSize = uint32(1024 * 1024)
  58. DefaultMinimumPoW = 0.2
  59. padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol
  60. messageQueueLimit = 1024
  61. expirationCycle = time.Second
  62. transmissionCycle = 300 * time.Millisecond
  63. DefaultTTL = 50 // seconds
  64. DefaultSyncAllowance = 10 // seconds
  65. )
  66. type unknownVersionError uint64
  67. func (e unknownVersionError) Error() string {
  68. return fmt.Sprintf("invalid envelope version %d", uint64(e))
  69. }
  70. // MailServer represents a mail server, capable of
  71. // archiving the old messages for subsequent delivery
  72. // to the peers. Any implementation must ensure that both
  73. // functions are thread-safe. Also, they must return ASAP.
  74. // DeliverMail should use directMessagesCode for delivery,
  75. // in order to bypass the expiry checks.
  76. type MailServer interface {
  77. Archive(env *Envelope)
  78. DeliverMail(whisperPeer *Peer, request *Envelope)
  79. }