use broadcast address

This commit is contained in:
study-faraphel 2024-11-10 13:09:58 +01:00
parent 3d38302e2f
commit 0745b725a7
5 changed files with 12 additions and 11 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.idea .idea
cmake-build-* cmake-build-*
assets

View file

@ -1,7 +1,9 @@
FROM alpine:latest FROM alpine:latest
RUN apk add gcc g++ cmake ninja RUN apk add gcc g++ cmake ninja
RUN apk add mpg123-dev openssl-dev portaudio-dev RUN apk add mpg123-dev openssl-dev alsa-lib alsa-utils portaudio-dev pulseaudio-alsa alsa-plugins-pulse pulseaudio pulseaudio-utils
RUN echo "pcm.!default pulse\nctl.!default pulse" > /root/.asoundrc
WORKDIR /app WORKDIR /app
COPY . /app COPY . /app

View file

@ -40,7 +40,7 @@ EventManager::EventManager() {
// hints for the communication // hints for the communication
addrinfo addressHints {}; addrinfo addressHints {};
addressHints.ai_family = AF_INET; // TODO: AF_INET6 addressHints.ai_family = AF_INET6;
addressHints.ai_socktype = SOCK_DGRAM; addressHints.ai_socktype = SOCK_DGRAM;
addressHints.ai_protocol = IPPROTO_UDP; addressHints.ai_protocol = IPPROTO_UDP;
@ -57,7 +57,7 @@ EventManager::EventManager() {
// get the information for the broadcast local-link address // get the information for the broadcast local-link address
// TODO(Faraphel): ip / port as argument ? // TODO(Faraphel): ip / port as argument ?
if(const int error = getaddrinfo( if(const int error = getaddrinfo(
"0.0.0.0", // TODO: ff02::1 "ff02::1",
"5650", "5650",
&addressHints, &addressHints,
&context.broadcastAddressInfo &context.broadcastAddressInfo
@ -105,7 +105,7 @@ void EventManager::loopSender() {
// get the information for the broadcast local-link address // get the information for the broadcast local-link address
// TODO(Faraphel): ip / port as argument ? // TODO(Faraphel): ip / port as argument ?
if(const int error = getaddrinfo( if(const int error = getaddrinfo(
"localhost", // TODO: ff02::1 "ff02::1",
"5650", "5650",
&addressHints, &addressHints,
&destinationInfo &destinationInfo
@ -148,7 +148,7 @@ void EventManager::loopReceiver() {
// TODO(Faraphel): port as argument // TODO(Faraphel): port as argument
addrinfo* senderInfo; addrinfo* senderInfo;
if(getaddrinfo( if(getaddrinfo(
"0.0.0.0", // hostname "ff02::1", // hostname
"5650", // port "5650", // port
&addressHints, &addressHints,
&senderInfo &senderInfo

View file

@ -6,8 +6,7 @@
#include <iostream> #include <iostream>
#include <numeric> #include <numeric>
#include <thread> #include <thread>
#include <bits/ranges_util.h> #include <algorithm>
#include <pstl/glue_numeric_defs.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "../../Context.hpp" #include "../../Context.hpp"
@ -43,9 +42,8 @@ void UndefinedTask::handle(Context& context) {
// TODO(Faraphel): should use the machine with the lowest average ping // TODO(Faraphel): should use the machine with the lowest average ping
if (context.me.serverEnabled) { if (context.me.serverEnabled) {
// find the remote peer with the highest id that can be a server // find the remote peer with the highest id that can be a server
const auto serverCandidate = std::max_element( const auto serverCandidate = std::ranges::max_element(
context.remotePeers.begin(), context.remotePeers,
context.remotePeers.end(),
[&](auto& remotePeer1, auto& remotePeer2) { [&](auto& remotePeer1, auto& remotePeer2) {
return ( return (
(remotePeer1.second->information.serverEnabled ? remotePeer1.first : 0) < (remotePeer1.second->information.serverEnabled ? remotePeer1.first : 0) <