Node.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Hoa
  4. *
  5. *
  6. * @license
  7. *
  8. * New BSD License
  9. *
  10. * Copyright © 2007-2017, Hoa community. All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * * Neither the name of the Hoa nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. namespace Hoa\Socket;
  36. /**
  37. * Class \Hoa\Socket\Node.
  38. *
  39. * Represent a generic node.
  40. *
  41. * @copyright Copyright © 2007-2017 Hoa community
  42. * @license New BSD License
  43. */
  44. class Node
  45. {
  46. /**
  47. * Node's ID.
  48. *
  49. * @var string
  50. */
  51. protected $_id = null;
  52. /**
  53. * Node's socket resource.
  54. *
  55. * @var resource
  56. */
  57. private $_socket = null;
  58. /**
  59. * Get server.
  60. *
  61. * @var \Hoa\Socket\Connection
  62. */
  63. private $_connection = null;
  64. /**
  65. * Encryption type.
  66. *
  67. * @var int
  68. */
  69. protected $_encryptionType = null;
  70. /**
  71. * Constructor.
  72. *
  73. * @param string $id ID.
  74. * @param resource $socket Socket.
  75. * @param \Hoa\Socket\Connection $connection Connection.
  76. */
  77. public function __construct($id, $socket, Connection $connection)
  78. {
  79. $this->_id = $id;
  80. $this->_socket = $socket;
  81. $this->_connection = $connection;
  82. return;
  83. }
  84. /**
  85. * Get node's ID.
  86. *
  87. * @return string
  88. */
  89. public function getId()
  90. {
  91. return $this->_id;
  92. }
  93. /**
  94. * Get node's socket resource.
  95. *
  96. * @return resource
  97. */
  98. public function getSocket()
  99. {
  100. return $this->_socket;
  101. }
  102. /**
  103. * Get connection.
  104. *
  105. * @return \Hoa\Socket\Connection
  106. */
  107. public function getConnection()
  108. {
  109. return $this->_connection;
  110. }
  111. /**
  112. * Set encryption type.
  113. *
  114. * @param int $type Type of encryption (please, see ENCRYPTION_*
  115. * constants from Hoa\Socket\Client and
  116. * Hoa\Socket\Server).
  117. * @return int
  118. */
  119. public function setEncryptionType($type)
  120. {
  121. $old = $this->_encryptionType;
  122. $this->_encryptionType = $type;
  123. return $old;
  124. }
  125. /**
  126. * Get encryption type.
  127. *
  128. * @return int
  129. */
  130. public function getEncryptionType()
  131. {
  132. return $this->_encryptionType;
  133. }
  134. }