Home | History | Annotate | Download | only in netprotos
      1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """
      6 netprotos - Network Protocols
      7 
      8 This module includes Python implementations of various network protocols to
      9 use in testing. These protocols can be used either with the kernel network
     10 stack openning UDP, TCP or RAW sockets or with the simulated network stack
     11 based on the lansim package.
     12 
     13 In either case, the interface used requires a Host object providing the
     14 following interface:
     15  * Host.ip_addr property, with the host's IP address in plain text.
     16  * Host.socket(family, sock_type) that returns a new asynchronous socket.
     17 
     18 An asynchronous socket must have the following interface:
     19  * listen(ip_addr, port, recv_callback)
     20  * send(data, ip_addr, port)
     21  * close()
     22 
     23 See lansim.host.UDPSocket for details on the utilization of this interface.
     24 Note that this interface is asynchronous since there's no blocking recv()
     25 method. Instead, when the main loop event handler receives a packet for
     26 this socket, the recv_callback passed will be called.
     27 
     28 
     29 To create new protocols you can follow the example of ZeroconfDaemon and
     30 CrosP2PDaemon which implement part of those protocols to serve files on
     31 the LAN.
     32 
     33 To launch a ZeroconfDaemon on a simulated Host, simply create that
     34 object for the given Host instance as follows:
     35 
     36     zero = zeroconf.ZeroconfDaemon(host_b, "host-name-b")
     37 
     38 Once again, a CrosP2PDaemon requires a ZeroconfDaemon instance to
     39 interact with, so simply creating the object will make it available.
     40 Although it is not sharing any file it anounces the num_connections
     41 attribute among other mDNS records required for P2P to work.
     42 
     43     p2p = cros_p2p.CrosP2PDaemon(zero)
     44 
     45 To add files and share them on the P2P server, the interface is the
     46 following:
     47 
     48     p2p.add_file('some_payload', 3000)
     49     p2p.add_file('other_payload', 6000)
     50 
     51 """
     52