p2p

package
v0.0.0-...-683b059 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package p2p contains the common code for P2P tests.

The most challenging part of P2P tests is that the P2P protocol uses multicasts for DNS-SD, but multicasts do not work properly with loopback network interfaces.

To tackle with the problem, we use network namespaces. We set up an isolated network namespace named "tastns", create virtual network interface pair connecting tastns and the default network namespace, and run avahi-daemon in tastns. Tast test process runs in the default namespace. This way we can make sure multicast packets go through routing instead of loopback.

Note that p2p_server and p2p_client also run in the default namespace, but they communicate with avahi-daemon running in tastns via D-Bus IPC, so they work just as if they are in tastns.

Below is a diagram illustrating the setup.

[Default network namespace] +------------------+-------------+
                            |                  |             |
     +--------+      +--------------+  +--------------+      |
     |  Tast  |----->|  p2p_server  |  |  p2p_client  |      |
     +--------+ HTTP +--------------+  +--------------+      |
          |                                                  | D-Bus
     +------------------------------------------------+      |  IPC
     |         veth-default (169.254.100.1)           |      |
     +------------------------------------------------+      |
                            | mDNS/DNS-SD                    |
----------------------------+-----------------------------------------
                            |                                |
     +------------------------------------------------+      |
     |         veth-isolated (169.254.100.2)          |      |
     +------------------------------------------------+      |
                            |                                |
                    +----------------+                       |
                    |  avahi-daemon  |<----------------------+
                    +----------------+

[Isolated network namespace "tastns"]

Note that it would be more preferable to run the Tast test process, instead of avahi-daemon, in an isolated network namespace, because it is more similar to the real configurations (e.g. iptables rules apply to avahi-daemon). But it is difficult to make the Tast test process enter a network namespace since setns(2) works per-thread but Go programs do not have a way to call system calls on all threads at once. See the following issues for details:

https://github.com/vishvananda/netns/issues/17
https://github.com/golang/go/issues/1435

Index

Constants

View Source
const (
	// ServiceType is the type of the P2P service (in terms of DNS-SD).
	ServiceType = "_cros_p2p._tcp"

	// ServicePort is the TCP port number where p2p-http-server serves HTTP
	// requests by default.
	ServicePort = 16725

	// SharedDir is the directory to hold the files served by p2p-http-server.
	SharedDir = "/var/cache/p2p"

	// NSName is the name of an isolated network namespace P2P tests create to
	// run avahi-daemon in.
	NSName = "tastns"

	// DefaultNSIP is the primary IPv4 address of the virtual network interface in
	// the default network namespace where Tast test process runs.
	DefaultNSIP = "169.254.100.1"

	// IsolatedNSIP is the IPv4 address of the virtual network interface in the
	// "tastns" network namespace where avahi-daemon runs.
	IsolatedNSIP = "169.254.100.2"
)

Variables

This section is empty.

Functions

func CleanUp

func CleanUp(ctx context.Context) error

CleanUp does some cleanup for P2P tests.

func SetUp

func SetUp(ctx context.Context) error

SetUp does some setup for P2P tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL