---
# System prepended metadata

title: Voip system

---

# Voip system

Some users and companies have a need to talk to others, but there are no providers available, at least early on. To sattisfy this need we have to provide our own solution. We will even get paid for doing so. 

In this guide I will describe how it works, how to set it up and how to troubleshoot issues with it.

## How it works

When users have a need they will look for a suitable provider. To do so they will pick a web service they want to visit that should provide all required functions. In case of voice the need is `stream-voice`. When they decide on the service they want to use, they will try to resolve the network adress using dns and then try to reach the server to consume 1 `stream-voice` use. If successful the need will be satisfied.

For a server to provide `stream-voice` use it needs to be running `voip-server` program and has to be connected to the phone.

> #### Common misconception
> It is the phone that sends data to the server, not the other way around, every few seconds phones will broadcast udp/5060 packet with no set destination in search of `[accept-voip-phone-connection]`. It is this packet that gets turned into stream-voice on the server so routing of communication is from PHONE -> SERVER not the other way around.

This means we need to do several things.
 * install a server running `voip-server` program
 * register a domain and advertise provided use
 * map the domain to the server
 * connect phone to the server running `voip-server` program
 * create connection between user and the server and route traffic

## Step by step guide:

#### 1) install voip-server program on a server

Buy or find a server you want to use with at least 5 cpu, 2 memory and 5 storage. Place it where you want it to go. 

I will purchase a "MacroHard Boulder+ SRV" and place it within a datacenter (in this case, floor 0).
![image](https://hackmd.io/_uploads/SJGK6GZOxl.png)

Connect it to power and connect the debugger to it. Right click the server to copy it's hwaddress (Hardware address). paste that adress in place of \<hwaddress>
    
run
```
net address set @voip on <hwaddress>
program install voip-server on <hwaddress>
dstat <hwaddress>
```

Confirm that the program is running and that the server has 
`[accept-voip-phone-connection] = 10` uses

#### 2) register a domain

If needed buy **The Registry** app from **Rocket store**.
Open the registry app and click register new domain.
Set the name and price (1.0 seems to work fine) and make sure to assosiate `stream-voice` usage with the domain. I will call mine `myvoice.net`.

![image](https://hackmd.io/_uploads/HJV-MX-dee.png)

> #### Common error
> make sure the assosiated use is stream-voice, not stream-audio or other simmilar one.

Click "Finalize" and "Confirm".

#### 3) map the domain to the server

We now need to map our domain to the server.

Run:
```
map myvoice.net as @voip
``` 

> remember to use the domain name and server name you used when setting things up in previous steps.

#### 4) connect phone to the server

This step will depend a lot on how your network looks. If you are using only switches you just need to connect the cables and the phone will reach the server. If you are using routers. On each router between phone and a server make sure to route traffic apropriately.

> **Remember**
> It is the phone that tires to reach the server not the other way arond so route traffic from PHONE -> SERVER

To route the traffic you can use routing by traffic type. voip traffic is `udp/5060` so on each router along the way run:
```
route add traffic udp/5060 via portX
```
where portX is port to which another server on the route or server itself is connected.
> make sure the traffic type is exactly udp/5060 (with forward slash)

Make sure phone requests can reach the server by using
```
dstat @voip
```
or
```
watch
```
and hover over the server

if done correctly server should start generating `stream-voice` uses 
![image](https://hackmd.io/_uploads/H1VlIXZuxl.png)

#### 5) connect clients to the server

connect clients to the server similarly to how you did with the phone.
Packets from clients requesting `stream-voice` will also be traffic type udp/5060 so most of the route should already work. Other wise add apropriate rules mapping either by destination `@voip` or by traffic type `udp/5060`. If done correctly users should have their need sattisfied.

### Final notes

The more phones you connect to the network the faster you will be generating `stream-voice` uses (limited by how fast you generate accept-voip-phone-connection). 

When trooubleshooting connection from client to server you can connect debbuger to where the clinet is and trace from that device with
```
trace @voip from <start_device> with udp/5060
```

## Diagram



![voip-tutorial](https://hackmd.io/_uploads/BkGztQW_xl.png)
