2L-MODS is a Python program that enables users to build and manage peer-to-peer (P2P) networks easily. It allows peers to connect, communicate, and maintain connections within a network.
- Establishes P2P connections using NAT traversal techniques.
- Maintains a list of peers and their IP addresses.
- Handles dynamic peer updates to keep the network connected.
- Provides basic client-server messaging capabilities.
- Python 3.x
- Required Python packages:
socket,threading,time,json - External packages:
requests,pystun3
-
Clone this repository:
git clone https://github.com/KTT-Projects/2L-MODS.git cd 2l-MODS -
Install the necessary Python packages:
pip install requests pystun3
Ensure you have a data_from_php.json file in the same directory with the following structure:
{
"network_name": "test",
"peers": [
{
"ip": "Your Public IP Here",
"port": Your Public UDP Port Here,
"nat_type": "server_ok"
},
{
"ip": "Your Public IP Here",
"port": Your Public UDP Port Here,
"nat_type": "server_no" (When Symmetric NAT is in use)
}
],
"model_distributor": {
"ip": "Your Public IP Here",
"port": Your Public UDP Port Here
}
}To start the program, run:
python main.py- Enter the network name and password when prompted.
- The program will determine the NAT type, external IP, and port.
- If the NAT type is not "Symmetric NAT", the program will start a server thread to listen for incoming connections.
- The program will attempt to connect to the network using the provided credentials.
- The program will display active connections as a client and periodically update the peer list.
main.py: The main script to start the P2P network builder.network.py: Contains the functionget_nat_type()to get the NAT type, external IP, and port.server.py: Contains the server implementation to handle incoming client connections.client.py: Contains the client implementation to handle outgoing server connections.config.py: Configuration constants such asSIZE,TEST_MESSAGE,IGNORE_MESSAGE.data_from_php.json: Contains the network configuration data.
get_config_data(network_name, password): Retrieves network configuration data fromdata_from_php.json.connect_to_network(network_name, password, nat_type, external_ip, external_port): Connects to the P2P network.update_peers(network_name, password, nat_type, external_ip, external_port): Periodically updates the peer list.main(): The main function to start the program.
send_to_client(server_socket, addr, msg): Sends a message to a client.recieve_from_client(server_socket, peers_ip): Receives messages from clients.start_server(external_port, peers_ip): Starts the server to listen for client connections.
receive_from_server(client_socket): Receives messages from the server.send_to_server(server_ip, server_port, data): Sends a message to the server.test_connection(server_ip, server_port): Tests the connection to a server.
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
For questions or support, please contact info@kttprojects.com.