VirtualNetworkRoute.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. package com.zerotier.sdk;
  28. import java.net.InetSocketAddress;
  29. public final class VirtualNetworkRoute implements Comparable<VirtualNetworkRoute>
  30. {
  31. private VirtualNetworkRoute() {
  32. target = null;
  33. via = null;
  34. flags = 0;
  35. metric = 0;
  36. }
  37. /**
  38. * Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default
  39. */
  40. public InetSocketAddress target;
  41. /**
  42. * Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway)
  43. */
  44. public InetSocketAddress via;
  45. /**
  46. * Route flags
  47. */
  48. public int flags;
  49. /**
  50. * Route metric (not currently used)
  51. */
  52. public int metric;
  53. @Override
  54. public int compareTo(VirtualNetworkRoute other) {
  55. return target.toString().compareTo(other.target.toString());
  56. }
  57. public boolean equals(VirtualNetworkRoute other) {
  58. boolean targetEquals;
  59. if (target == null && other.target == null) {
  60. targetEquals = true;
  61. }
  62. else if (target == null && other.target != null) {
  63. targetEquals = false;
  64. }
  65. else if (target != null && other.target == null) {
  66. targetEquals = false;
  67. }
  68. else {
  69. targetEquals = target.equals(other.target);
  70. }
  71. boolean viaEquals;
  72. if (via == null && other.via == null) {
  73. viaEquals = true;
  74. }
  75. else if (via == null && other.via != null) {
  76. viaEquals = false;
  77. }
  78. else if (via != null && other.via == null) {
  79. viaEquals = false;
  80. }
  81. else {
  82. viaEquals = via.equals(other.via);
  83. }
  84. return viaEquals &&
  85. viaEquals &&
  86. flags == other.flags &&
  87. metric == other.metric;
  88. }
  89. }