You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

  1. package p2p
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. // ErrSwitchDuplicatePeerID to be raised when a peer is connecting with a known
  7. // ID.
  8. type ErrSwitchDuplicatePeerID struct {
  9. ID ID
  10. }
  11. func (e ErrSwitchDuplicatePeerID) Error() string {
  12. return fmt.Sprintf("Duplicate peer ID %v", e.ID)
  13. }
  14. // ErrSwitchDuplicatePeerIP to be raised whena a peer is connecting with a known
  15. // IP.
  16. type ErrSwitchDuplicatePeerIP struct {
  17. IP net.IP
  18. }
  19. func (e ErrSwitchDuplicatePeerIP) Error() string {
  20. return fmt.Sprintf("Duplicate peer IP %v", e.IP.String())
  21. }
  22. // ErrSwitchConnectToSelf to be raised when trying to connect to itself.
  23. type ErrSwitchConnectToSelf struct {
  24. Addr *NetAddress
  25. }
  26. func (e ErrSwitchConnectToSelf) Error() string {
  27. return fmt.Sprintf("Connect to self: %v", e.Addr)
  28. }
  29. type ErrSwitchAuthenticationFailure struct {
  30. Dialed *NetAddress
  31. Got ID
  32. }
  33. func (e ErrSwitchAuthenticationFailure) Error() string {
  34. return fmt.Sprintf(
  35. "Failed to authenticate peer. Dialed %v, but got peer with ID %s",
  36. e.Dialed,
  37. e.Got,
  38. )
  39. }
  40. //-------------------------------------------------------------------
  41. type ErrNetAddressNoID struct {
  42. Addr string
  43. }
  44. func (e ErrNetAddressNoID) Error() string {
  45. return fmt.Sprintf("Address (%s) does not contain ID", e.Addr)
  46. }
  47. type ErrNetAddressInvalid struct {
  48. Addr string
  49. Err error
  50. }
  51. func (e ErrNetAddressInvalid) Error() string {
  52. return fmt.Sprintf("Invalid address (%s): %v", e.Addr, e.Err)
  53. }
  54. type ErrNetAddressLookup struct {
  55. Addr string
  56. Err error
  57. }
  58. func (e ErrNetAddressLookup) Error() string {
  59. return fmt.Sprintf("Error looking up host (%s): %v", e.Addr, e.Err)
  60. }