Skip to content

Commit 6c13c36

Browse files
authored
Add NODE_X syntax to specify network nodes (#461)
1 parent 58dc347 commit 6c13c36

File tree

11 files changed

+148
-75
lines changed

11 files changed

+148
-75
lines changed

share/logcfg.dat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ TIME_MASTER
6868
#################################
6969
# use 'addnode' only for OTHER nodes !!
7070
#
71-
#ADDNODE=10.0.0.115
72-
#ADDNODE=192.168.1.2
71+
#NODE_B=10.0.0.115
72+
#NODE_C=192.168.1.2
7373
#
7474
THISNODE=A
7575
#

src/changepars.c

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -689,38 +689,57 @@ void networkinfo(void) {
689689

690690
wipe_display();
691691

692-
if (lan_active)
692+
int n_nodes = 0;
693+
694+
if (lan_active) {
693695
mvprintw(1, 10, "Network status: on Node: %c", thisnode);
694-
else
695-
mvaddstr(1, 10, "Network status: off");
696+
mvprintw(3, 32, "Total packets rcvd: %d | %d", recv_packets, recv_error);
696697

697-
mvprintw(3, 22, "Total packets rcvd: %d | %d", recv_packets, recv_error);
698+
for (int i = 0; i < nodes; i++) {
699+
if (*bc_hostaddress[i] == 0) {
700+
continue;
701+
}
702+
GString *info = g_string_new(NULL);
703+
int column = 10;
704+
if (using_named_nodes) {
705+
char *id = g_strdup_printf("%c%c) ",
706+
(i == thisnode - 'A' ? '*' : ' '),
707+
'A' + i
708+
);
709+
g_string_append(info, id);
710+
g_free(id);
711+
column -= 4;
712+
}
713+
g_string_append(info, bc_hostaddress[i]);
714+
if (bc_hostport[i] > 0) {
715+
char *port = g_strdup_printf(":%d", bc_hostport[i]);
716+
g_string_append(info, port);
717+
g_free(port);
718+
}
719+
char *s = g_string_free(info, FALSE);
720+
mvaddstr(4 + n_nodes, column, s);
721+
g_free(s);
698722

699-
for (int i = 0; i < nodes; i++) {
700-
mvaddstr(4 + i, 10, bc_hostaddress[i]);
701-
mvprintw(4 + i, 28, "Packets sent: %d | %d ",
702-
send_packets[i], send_error[i]);
723+
mvprintw(4 + n_nodes, 38, "Packets sent: %d | %d ",
724+
send_packets[i], send_error[i]);
725+
++n_nodes;
726+
}
727+
} else {
728+
mvaddstr(1, 10, "Network status: off");
703729
}
704730

705-
if (strlen(config_file) > 0)
706-
mvprintw(6 + nodes, 10, "Config file: %s", config_file);
707-
else
708-
mvprintw(6 + nodes, 10,
709-
"Config file: /usr/local/share/tlf/logcfg.dat");//FIXME
710-
mvprintw(7 + nodes, 10, "Contest : %s", whichcontest);
711-
mvprintw(8 + nodes, 10, "Logfile : %s", logfile);
712-
713-
mvprintw(9 + nodes, 10, "Cluster : %s", pr_hostaddress);
714-
mvprintw(10 + nodes, 10, "TNCport : %s", tncportname);
715-
mvprintw(11 + nodes, 10, "RIGport : %s", rigportname);
716-
if (use_bandoutput == 1)
717-
mvaddstr(12 + nodes, 10, "Band output: on");
718-
else
719-
mvaddstr(12 + nodes, 10, "Band output: off");
731+
mvprintw(6 + n_nodes, 10, "Config file: %s", config_file);
732+
mvprintw(7 + n_nodes, 10, "Contest : %s", whichcontest);
733+
mvprintw(8 + n_nodes, 10, "Logfile : %s", logfile);
720734

721-
mvprintw(13 + nodes, 10, "callmaster : %s",
735+
mvprintw(9 + n_nodes, 10, "Cluster : %s", pr_hostaddress);
736+
mvprintw(10 + n_nodes, 10, "TNCport : %s", tncportname);
737+
mvprintw(11 + n_nodes, 10, "RIGport : %s", rigportname);
738+
mvprintw(12 + n_nodes, 10, "Band output: %s",
739+
(use_bandoutput ? "on" : "off"));
740+
mvprintw(13 + n_nodes, 10, "callmaster : %s",
722741
(callmaster_version[0] != 0 ? callmaster_version : "n/a"));
723-
mvprintw(14 + nodes, 10, "cty.dat : %s",
742+
mvprintw(14 + n_nodes, 10, "cty.dat : %s",
724743
(cty_dat_version[0] != 0 ? cty_dat_version : "n/a"));
725744

726745
refreshp();

src/globalvars.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ extern int continentlist_points;
140140
extern int dx_cont_points;
141141
extern int my_cont_points;
142142
extern int packetinterface;
143-
extern int use_bandoutput;
143+
extern bool use_bandoutput;
144144
extern int cluster;
145145
extern int nodes;
146+
extern bool using_named_nodes;
146147
extern int multlist;
147148
extern int xplanet;
148149
extern int cwkeyer;

src/lancode.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ bool cl_send_inhibit = false;
4949
struct sockaddr_in bc_address[MAXNODES];
5050
/* host names and UDP ports to send notifications to */
5151
char bc_hostaddress[MAXNODES][16];
52-
char bc_hostservice[MAXNODES][16] = {
53-
[0 ... MAXNODES - 1] = { [0 ... 15] = 0 }
54-
};
52+
int bc_hostport[MAXNODES];
5553
int nodes = 0;
54+
bool using_named_nodes;
5655
//--------------------------------------
5756
/* default port to listen for incoming packets and to send packet to */
58-
char default_lan_service[16] = "6788";
59-
/* lan port parsed from config */
60-
int lan_port = 6788;
57+
/* can be changed using LAN_PORT config */
58+
int lan_port;
6159

6260
bool lan_active = false;
6361
int send_error[MAXNODES];
@@ -76,21 +74,6 @@ char thisnode = 'A'; /* start with 'A' if not defined in
7674

7775
//---------------------end lan globals --------------
7876

79-
int resolveService(const char *service) {
80-
struct servent *service_ent;
81-
service_ent = getservbyname(service, "udp");
82-
int port = 0;
83-
if (service_ent != NULL) {
84-
port = ntohs(service_ent->s_port);
85-
} else if (strlen(service) > 0) {
86-
port = atoi(service);
87-
}
88-
if (port == 0) {
89-
port = atoi(default_lan_service);
90-
}
91-
return port;
92-
}
93-
9477
int lan_recv_init(void) {
9578
int lan_bind_rc;
9679
long lan_save_file_flags;
@@ -99,11 +82,13 @@ int lan_recv_init(void) {
9982
if (!lan_active)
10083
return 0;
10184

102-
sprintf(default_lan_service, "%d", lan_port);
85+
int node = thisnode - 'A';
86+
int port = (bc_hostport[node] > 0 ? bc_hostport[node] : lan_port);
87+
10388
bzero(&lan_sin, sizeof(lan_sin));
10489
lan_sin.sin_family = AF_INET;
10590
lan_sin.sin_addr.s_addr = htonl(INADDR_ANY);
106-
lan_sin.sin_port = htons(resolveService(default_lan_service));
91+
lan_sin.sin_port = htons(port);
10792

10893
lan_socket_descriptor = socket(AF_INET, SOCK_DGRAM, 0);
10994
if (lan_socket_descriptor == -1) {
@@ -186,6 +171,12 @@ int lan_send_init(void) {
186171
return 0;
187172

188173
for (int node = 0; node < nodes; node++) {
174+
if (*bc_hostaddress[node] == 0) {
175+
continue;
176+
}
177+
if (using_named_nodes && node == thisnode - 'A') {
178+
continue; // skip ourserlves
179+
}
189180

190181
bc_hostbyname[node] = gethostbyname(bc_hostaddress[node]);
191182
if (bc_hostbyname[node] == NULL) {
@@ -198,7 +189,8 @@ int lan_send_init(void) {
198189
memcpy(&bc_address[node].sin_addr.s_addr, bc_hostbyname[node]->h_addr,
199190
sizeof(bc_address[node].sin_addr.s_addr));
200191

201-
bc_address[node].sin_port = htons(resolveService(bc_hostservice[node]));
192+
int port = (bc_hostport[node] > 0 ? bc_hostport[node] : lan_port);
193+
bc_address[node].sin_port = htons(port);
202194

203195
syslog(LOG_INFO, "open socket: to %d.%d.%d.%d:%d\n",
204196
(ntohl(bc_address[node].sin_addr.s_addr) & 0xff000000) >> 24,
@@ -246,6 +238,12 @@ static int lan_send(char *lanbuffer) {
246238
}
247239

248240
for (int node = 0; node < nodes; node++) {
241+
if (*bc_hostaddress[node] == 0) {
242+
continue;
243+
}
244+
if (using_named_nodes && node == thisnode - 'A') {
245+
continue; // skip ourserlves
246+
}
249247

250248
bc_sendto_rc = sendto(bc_socket_descriptor[node],
251249
lanbuffer, strlen(lanbuffer),

src/lancode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#include <hamlib/rig.h>
8585

8686
extern char bc_hostaddress[MAXNODES][16];
87-
extern char bc_hostservice[MAXNODES][16];
87+
extern int bc_hostport[MAXNODES];
8888
extern char talkarray[5][62];
8989
extern char thisnode;
9090
extern char lan_message[256];

src/main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int tlfcolors[8][2] = { {COLOR_BLACK, COLOR_WHITE},
9191
bool debugflag = false;
9292
char *editor_cmd = NULL;
9393
int tune_val = 0;
94-
int use_bandoutput = 0;
94+
bool use_bandoutput = false;
9595
bool no_arrows = false;
9696
int bandindexarray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
9797
bool cqwwm2 = false;
@@ -644,6 +644,7 @@ static void init_variables() {
644644
portnum = 0;
645645
packetinterface = 0;
646646
nodes = 0;
647+
using_named_nodes = false;
647648
shortqsonr = 0;
648649
tune_seconds = 6; /* tune up for 6 s */
649650
unique_call_multi = MULT_NONE;
@@ -655,6 +656,14 @@ static void init_variables() {
655656
resend_call = RESEND_NOT_SET;
656657
cwstart = 0; // off
657658
rig_mode_sync = true;
659+
use_bandoutput = false;
660+
661+
lan_active = false;
662+
thisnode = 'A';
663+
lan_port = 6788;
664+
bzero(bc_hostaddress, sizeof(bc_hostaddress));
665+
bzero(bc_hostport, sizeof(bc_hostport));
666+
time_master = false;
658667

659668
g_free(current_qso.call);
660669
current_qso.call = g_malloc0(CALL_SIZE);

src/parse_logcfg.c

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int cfg_bandoutput(const cfg_arg_t arg) {
474474

475475
if (g_regex_match_simple("^\\d{10}$", str, G_REGEX_CASELESS,
476476
(GRegexMatchFlags)0)) {
477-
use_bandoutput = 1;
477+
use_bandoutput = true;
478478
for (int i = 0; i <= 9; i++) { // 10x
479479
bandindexarray[i] = str[i] - '0';
480480
}
@@ -612,26 +612,58 @@ static int cfg_tncport(const cfg_arg_t arg) {
612612
return PARSE_OK;
613613
}
614614

615-
static int cfg_addnode(const cfg_arg_t arg) {
616-
if (nodes >= MAXNODES) {
617-
error_details = g_strdup_printf("max %d nodes allowed", MAXNODES);
618-
return PARSE_WRONG_PARAMETER;
619-
}
615+
static void parse_node(int index) {
620616
/* split host name and port number, separated by colon */
621617
char **an_fields;
622618
an_fields = g_strsplit(parameter, ":", 2);
623619
/* copy host name */
624-
g_strlcpy(bc_hostaddress[nodes], g_strchomp(an_fields[0]),
620+
g_strlcpy(bc_hostaddress[index], g_strchomp(an_fields[0]),
625621
sizeof(bc_hostaddress[0]));
626622
if (an_fields[1] != NULL) {
627623
/* copy host port, if found */
628-
g_strlcpy(bc_hostservice[nodes], g_strchomp(an_fields[1]),
629-
sizeof(bc_hostservice[0]));
624+
bc_hostport[index] = atoi(an_fields[1]);
630625
}
631626
g_strfreev(an_fields);
632627

633-
nodes++;
634628
lan_active = true;
629+
}
630+
631+
static int cfg_addnode(const cfg_arg_t arg) {
632+
if (using_named_nodes) {
633+
error_details = g_strdup("already using named nodes");
634+
return PARSE_WRONG_PARAMETER;
635+
}
636+
if (nodes >= MAXNODES) {
637+
error_details = g_strdup_printf("max %d nodes allowed", MAXNODES);
638+
return PARSE_WRONG_PARAMETER;
639+
}
640+
641+
parse_node(nodes);
642+
nodes++;
643+
644+
return PARSE_OK;
645+
}
646+
647+
static int cfg_node_x(const cfg_arg_t arg) {
648+
gchar *x = g_match_info_fetch(match_info, 1);
649+
int index = *x - 'A';
650+
g_free(x);
651+
652+
if (index >= MAXNODES) {
653+
error_details = g_strdup_printf("name is A..%c", 'A' + MAXNODES - 1);
654+
return PARSE_WRONG_PARAMETER;
655+
}
656+
if (!using_named_nodes && nodes > 0) {
657+
error_details = g_strdup("already using unnamed nodes");
658+
return PARSE_WRONG_PARAMETER;
659+
}
660+
661+
using_named_nodes = true;
662+
663+
parse_node(index);
664+
if (index + 1 > nodes) {
665+
nodes = index + 1;
666+
}
635667

636668
return PARSE_OK;
637669
}
@@ -1411,6 +1443,7 @@ static config_t logcfg_configs[] = {
14111443
{"SFI", NEED_PARAM, cfg_sfi},
14121444
{"TNCPORT", NEED_PARAM, cfg_tncport},
14131445
{"ADDNODE", NEED_PARAM, cfg_addnode},
1446+
{"NODE_([A-Z])", NEED_PARAM, cfg_node_x},
14141447
{"THISNODE", NEED_PARAM, cfg_thisnode},
14151448
{"MULT_LIST", NEED_PARAM, cfg_mult_list},
14161449
{"MARKER(|DOT|CALL)S", NEED_PARAM, cfg_markers},

test/data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool debugflag = false;
5454
char *editor_cmd = NULL;
5555
char rttyoutput[120];
5656
int tune_val = 0;
57-
int use_bandoutput = 0;
57+
bool use_bandoutput = false;
5858
bool no_arrows = false;
5959
int bandindexarray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
6060
bool cqwwm2 = false;

test/test_lancode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ int setup_default(void **state) {
2323
trx_control = true;
2424
nodes = 1;
2525
lan_active = true;
26+
using_named_nodes = false;
27+
strcpy(bc_hostaddress[0], "host0");
2628

2729
sendto_call_count = 0;
2830
FREE_DYNAMIC_STRING(sendto_last_message);

0 commit comments

Comments
 (0)