You are on page 1of 15

ABSTRACT

Peer to Peer is a decentralized communication model in which each party has the same capabilities
and either party can initiate a request.The P2P network model allows each node to function as both
a client and server.Most of the P2P programs are focused on media sharing.P2P is therefore often
associated with Software piracy and copyright violation.By using network communication
session.Unlike the client /server model in which the client makes a service request and the server
full fills the coding the any node between source and destination are used to transfer the message.
Network coding is scheme in which node can generate output message by encoding the message
that received from the same node.Network coding aspires to improve parameter such as throughput
and reliability. . This is decided by the underlying architecture supported by the P2P systems. By
means of one of these methods, the client peer can get to know about all the peers which have the
requested object/file and the file transfer takes place directly between these two peers.

1|Page
INTRODUCTION

The project is C Based Peer to Peer( P2P) File Sharing System with chat. Point-to-Point
(P2P)technology enables the sharing of computer resources such as files by a direct exchange
between end-users computers. P2P networking means files are not stored on a central server.
Instead ,client software (such as the popular Kazaa, Lime wire) works as a server for shared files
on an individual's computer. This allows each computer with the software to act as a mini-server
from which other P2P users can download files. P2P's popularity stems from its easy-to-use,
convenient setup that has empowered informal networks of file sharers to make files available to
each other around the globe.P2P communication has the following characteristics:

Direct connections between network clients. Each client (node) is considered as an equal to all
others. Clients share processing, applications and content.SSS There is no central point of control
within the network. Peer-to-peer computing is the sharing of computer resources and services by
direct exchange between systems. In a peerto-peer architecture, computers that have traditionally
been used solely as clients communicate directly among themselves and can act as both clients and
a server, assuming whatever role is most efficient for the network.

Another big attraction of file-sharing is cost :


Users can download as many songs as they like from each other, for free. With the price of CDs
often well over $20, many music-lovers have engaged in file-sharing despite the legal risks
involved. Moreover, many consumers are loath to spend $20 for a compilation of songs when they
are really only interested in one of the tracks on the CD. They may turn to file-sharing in order to
download the one song that they want, without having to purchase the full CD.

Types of Peer To Peer Network:


Unstructured peer-to-peer network:
It do not impose any structure on the overlay networks. Peers in these networks connect in an ad-
hoc fashion. Ideally, unstructuredP2P systems would have absolutely no centralized system, but in
practice there are several types of unstructured systems with various degrees of centralization.
There are two main types of unstructured P2P networks:

Pure peer-to-peer systems :


The entire network consists solely of equipotent peers. There is only one routing layer, as there are
no preferred nodes with any special infrastructure function.

Hybrid peer-to-peer systems:


These systems allow such infrastructure nodes to exist, often called super nodes. A pure P2P
network does not have the notion of clients or servers but only equal peer nodes that simultaneously
function as both "clients" and "servers" to the other nodes on the network.
2|Page
Centralized peer-to-peer network:

In this, central server is used for indexing functions and to bootstrap the entire system. Although
this has similarities with a structured architecture, the connections between peers are not
determined by any algorithm.

How P2P works

A peer-to-peer network allows computer hardware and software to communicate without the
need for a server. Unlike client-server architecture, there is no central server for processing
requests in a P2P architecture. The peers directly interact with one another without the
requirement of a central server.
Now, when one peer makes a request, it is possible that multiple peers have the copy of that
requested object. Now the problem is how to get the IP addresses of all those peers. This is
decided by the underlying architecture supported by the P2P systems. By means of one of these
methods, the client peer can get to know about all the peers which have the requested object/file
and the file transfer takes place directly between these two peers.
Three such Architectures exist:
1. Centralized Directory
2. Query Flooding
3. Exploiting Heterogeneity

1. Centralized Directory
• It is somewhat similar to client server architecture in the sense that it maintains a huge central
server to provide directory service.
• All the peers inform this central server of their IP address and the files they are making
available for sharing.
• The server queries the peers at regular intervals to make sure if the peers are still connected

3|Page
3
• So basically this server maintains a huge database regarding which file is present at which
IP addresses.

Working
• Now whenever a requesting peer comes in, it sends its query to the server.
• Since the server has all the information of its peers, so it returns the IP addresses of all the
peers having the requested file to the peer.
• Now the file transfer takes place between these two peers.
The first system which made use of this method was Napster, for the purpose of Mp3
distribution.

The major problem with such an architecture is that there is a single point of failure. If the server
crashes, the whole P2P network crashes. Also, since all of the processing is to be done by a single
server so a huge amount of database has to be maintained and regularly updated.
1. Query Flooding
• Unlike the centralized approach, this method makes use of distributed systems.
• In this, the peers are supposed to be connected into an overlay network. It means if a
connection/path exists from one peer to other, it is a part of this overlay network.
• In this overlay network, peers are called as nodes and the connection between peers is called
an edge between the nodes, thus resulting in a graph-like structure.

Working

4|Page
• Now when one peer requests for some file, this request is sent to all its neighboring nodes
i.e. to all nodes which are connected to this node. If those nodes don’t have the required
file, they pass on the query to their neighbors and so on. This is called as query flooding.

• When the peer with requested file is found (referred to as query hit), the query flooding stops
and it sends back the file name and file size to the client, thus following the reverse path.
• If there are multiple query hits, the client selects from one of these peers.

Gnutella was the first decentralized peer to peer network.

This method also has some disadvantages like, the query has to be sent to all the neighbouring
peers unless a match is found. This increases traffic in the network.
2. Exploiting heterogeneity
• This P2P architecture makes use of both the above discussed systems.
• It resembles a distributed system like Gnutella because there is no central server for query
processing.
• But unlike Gnutella, it does not treat all its peers equally. The peers with higher bandwidth
and network connectivity are at a higher priority and are called as group leaders/super
nodes. The rest of the peers are assigned to these super nodes.
• These super nodes are interconnected and the peers under these super nodes inform their
respective leaders about their connectivity, IP address and the files available for sharing.

Working
• This structure can process the queries in two ways.

5|Page
• The first one is that the super nodes could contact other super nodes and merge their
databases with its own database. Thus, this super node now has information of a large
number of peers.
• Another approach is that when a query comes in, it is forwarded to the neighboring super
nodes until a match is found, just like in Gnutella. Thus query flooding exists but with
limited scope as each super node has many child peers. Hence, such a system exploits the
heterogeneity of the peers by designating some of them as group leaders/super nodes and
others as their child peers.

6|Page
SERVER CODE:

#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#define IP_PROTOCOL 0
#define PORT_NO 15050
#define NET_BUF_SIZE 32
#define cipherKey 'S'
#define sendrecvflag 0
#define nofile "File Not Found!"

// funtion to clear buffer


void clearBuf(char* b)
{
int i;
for (i = 0; i < NET_BUF_SIZE; i++)
b[i] = '\0';
}

// funtion to encrypt
char Cipher(char ch)
{
return ch ^ cipherKey;
}

// funtion sending file


int sendFile(FILE* fp, char* buf, int s)
{
int i, len;

7|Page
if (fp == NULL) {
strcpy(buf, nofile);
len = strlen(nofile);
buf[len] = EOF;
for (i = 0; i <= len; i++)
buf[i] = Cipher(buf[i]);
return 1;
}

char ch, ch2;


for (i = 0; i < s; i++) {
ch = fgetc(fp);
ch2 = Cipher(ch);
buf[i] = ch2;
if (ch == EOF)
return 1;
}
return 0;
}

// driver code
int main()
{
int sockfd, nBytes;
struct sockaddr_in addr_con;
int addrlen = sizeof(addr_con);
addr_con.sin_family = AF_INET;
addr_con.sin_port = htons(PORT_NO);
addr_con.sin_addr.s_addr = INADDR_ANY;
char net_buf[NET_BUF_SIZE];
FILE* fp;

// socket()
sockfd = socket(AF_INET, SOCK_DGRAM, IP_PROTOCOL);

if (sockfd < 0)
printf("\nfile descriptor not received!!\n");
else
printf("\nfile descriptor %d received\n", sockfd);

8|Page
// bind()
if (bind(sockfd, (struct sockaddr*)&addr_con, sizeof(addr_con)) == 0)
printf("\nSuccessfully binded!\n");
else
printf("\nBinding Failed!\n");

while (1) {
printf("\nWaiting for file name...\n");

// receive file name


clearBuf(net_buf);

nBytes = recvfrom(sockfd, net_buf,


NET_BUF_SIZE, sendrecvflag,
(struct sockaddr*)&addr_con, &addrlen);

fp = fopen(net_buf, "r");
printf("\nFile Name Received: %s\n", net_buf);
if (fp == NULL)
printf("\nFile open failed!\n");
else
printf("\nFile Successfully opened!\n");

while (1) {

// process
if (sendFile(fp, net_buf, NET_BUF_SIZE)) {
sendto(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag,
(struct sockaddr*)&addr_con, addrlen);
break;
}

// send
sendto(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag,
(struct sockaddr*)&addr_con, addrlen);
clearBuf(net_buf);
}
if (fp != NULL)

9|Page
fclose(fp);
}
return 0;
}
CLIENT CODE:

// client code for UDP socket programming


#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#define IP_PROTOCOL 0
#define IP_ADDRESS "127.0.0.1" // localhost
#define PORT_NO 15050
#define NET_BUF_SIZE 32
#define cipherKey 'S'
#define sendrecvflag 0

// funtion to clear buffer


void clearBuf(char* b)
{
int i;
for (i = 0; i < NET_BUF_SIZE; i++)
b[i] = '\0';
}

// function for decryption


char Cipher(char ch)
{
return ch ^ cipherKey;
}

// function to receive file


int recvFile(char* buf, int s)
{

10 | P a g e
int i;
char ch;
for (i = 0; i < s; i++) {
ch = buf[i];
ch = Cipher(ch);
if (ch == EOF)
return 1;
else
printf("%c", ch);
}
return 0;
}

// driver code
int main()
{
int sockfd, nBytes;
struct sockaddr_in addr_con;
int addrlen = sizeof(addr_con);
addr_con.sin_family = AF_INET;
addr_con.sin_port = htons(PORT_NO);
addr_con.sin_addr.s_addr = inet_addr(IP_ADDRESS);
char net_buf[NET_BUF_SIZE];
FILE* fp;

// socket()
sockfd = socket(AF_INET, SOCK_DGRAM,
IP_PROTOCOL);

if (sockfd < 0)
printf("\nfile descriptor not received!!\n");
else
printf("\nfile descriptor %d received\n", sockfd);

while (1) {
printf("\nPlease enter file name to receive:\n");
scanf("%s", net_buf);
sendto(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
addrlen);

11 | P a g e
printf("\n---------Data Received---------\n");

while (1) {
// receive
clearBuf(net_buf);
nBytes = recvfrom(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
&addrlen);

// process
if (recvFile(net_buf, NET_BUF_SIZE)) {
break;
}
}
printf("\n-------------------------------\n");
}
return 0;
}

12 | P a g e
OUTPUT:

13 | P a g e
CONCLUSION:

A peer-to-peer network allows computer hardware and software to communicate without the need
for a server. Unlike client-server architecture, there is no central server for processing requests in
a P2P architecture. The peers directly interact with one another without the requirement of a central
server.
Now, when one peer makes a request, it is possible that multiple peers have the copy of that
requested object. Now the problem is how to get the IP addresses of all those peers. This is decided
by the underlying architecture supported by the P2P systems. By means of one of these methods,
the client peer can get to know about all the peers which have the requested object/file and the file
transfer takes place directly between these two peers.

The major problem with such an architecture is that there is a single point of failure. If the server
crashes, the whole P2P network crashes. Also, since all of the processing is to be done by a single
server so a huge amount of database has to be maintained and regularly updated.

14 | P a g e
REFERENCES:

Title:
Peer To Peer File Transfer over LANs

Authors:
Mr. Samir Ashok Mohite

Cite This Article :

Mr. Samir Ashok Mohite "Peer To Peer File Transfer over LANs" Published in International
Journal of Trend in Scientific Research and Development (ijtsrd), ISSN: 2456-6470, Volume-2 |
Issue-4 , June 2018, pp.2821-2823, URL: http://www.ijtsrd.com/papers/ijtsrd15746.pdf

15 | P a g e

You might also like