-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
264 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
####################################################################################################################### | ||
# Author: Maurice Snoeren # | ||
# Version: 0.1 beta (use at your own risk) # | ||
# Version: 0.2 beta (use at your own risk) # | ||
# # | ||
# MyOwnPeer2PeerNode is an example how to use the p2pnet.Node to implement your own peer-to-peer network node. # | ||
# 28/06/2021: Added the new developments on id and max_connections | ||
####################################################################################################################### | ||
from p2pnetwork.node import Node | ||
|
||
class MyOwnPeer2PeerNode (Node): | ||
|
||
# Python class constructor | ||
def __init__(self, host, port): | ||
super(MyOwnPeer2PeerNode, self).__init__(host, port, None) | ||
def __init__(self, host, port, id=None, callback=None, max_connections=0): | ||
super(MyOwnPeer2PeerNode, self).__init__(host, port, id, callback, max_connections) | ||
print("MyPeer2PeerNode: Started") | ||
|
||
# all the methods below are called when things happen in the network. | ||
# implement your network node behavior to create the required functionality. | ||
|
||
def outbound_node_connected(self, node): | ||
print("outbound_node_connected: " + node.id) | ||
print("outbound_node_connected (" + self.id + "): " + node.id) | ||
|
||
def inbound_node_connected(self, node): | ||
print("inbound_node_connected: " + node.id) | ||
print("inbound_node_connected: (" + self.id + "): " + node.id) | ||
|
||
def inbound_node_disconnected(self, node): | ||
print("inbound_node_disconnected: " + node.id) | ||
print("inbound_node_disconnected: (" + self.id + "): " + node.id) | ||
|
||
def outbound_node_disconnected(self, node): | ||
print("outbound_node_disconnected: " + node.id) | ||
print("outbound_node_disconnected: (" + self.id + "): " + node.id) | ||
|
||
def node_message(self, node, data): | ||
print("node_message from " + node.id + ": " + str(data)) | ||
print("node_message (" + self.id + ") from " + node.id + ": " + str(data)) | ||
|
||
def node_disconnect_with_outbound_node(self, node): | ||
print("node wants to disconnect with other outbound node: " + node.id) | ||
print("node wants to disconnect with oher outbound node: (" + self.id + "): " + node.id) | ||
|
||
def node_request_to_stop(self): | ||
print("node is requested to stop!") | ||
print("node is requested to stop (" + self.id + "): ") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.