diff -urN clussed-19981224/CHANGELOG clussed-19981227/CHANGELOG --- clussed-19981224/CHANGELOG Thu Dec 24 17:59:22 1998 +++ clussed-19981227/CHANGELOG Sun Dec 27 13:20:40 1998 @@ -39,3 +39,27 @@ The #defines are in csock.h. What a great way to spend christmas eve? +Sun Dec 27 13:20:00 EET 1998 + + Added base2 directory. Wish it would have been this easy to run two + copies of Clusse on DOS back when I was writing it's PC linking code. + Added STRUCTURE "document". + Added some more links.conf parsing. + Added user commands: links, messages, commands, ? points to commands + Made nodes command work a bit better. + Made incoming links work, detection at luser_login(). + Wrote a lot of PC link parsing and sending code. + Wrote and rewrote a lot of networking code. + It does, somehow, manage to create a link now. ONLY tried it against + another instance of itself, DO NOT try it against a production + network just yet. + User and node lists (of 2 nodes, 2 users 8-) seem to work, and + so does PC10 (talk). Consept proven. + Implemented compressed outgoing connections ("compressed" keyword + in the connection script *before* the connection line). Now, the only + thing missing is switching to compressed mode after a certain C/R + line. + Fixed send_us() and made some of the cluster.c stubs call it to send + cluster events to users. Look ma, variable substitution! + + diff -urN clussed-19981224/Makefile clussed-19981227/Makefile --- clussed-19981224/Makefile Thu Dec 24 16:10:13 1998 +++ clussed-19981227/Makefile Sun Dec 27 03:25:24 1998 @@ -20,7 +20,7 @@ clean: @echo "Making clean ..." - rm -f *.o */*.o *~ */*~ core compile.h + rm -f *.o */*.o *~ */*~ */*/*~ core compile.h distclean: clean @echo "Making distclean ..." @@ -64,12 +64,12 @@ network.o net_link.o net_user.o net_ping.o net_rdb.o net_pc.o \ linker.o ui.o \ cfile.o f_dx.o f_ann.o f_wwv.o f_luser.o f_nuser.o f_last.o mid.o \ - lib/libax25.a CLUSSED_LIBS = -lm -lz -lgdbm +CLUSSED_SLIBS = lib/libax25.a clussed: $(CLUSSED_MODULES) - $(LD) -o clussed $(LDFLAGS) $(CLUSSED_LIBS) $(CLUSSED_MODULES) + $(LD) -o clussed $(LDFLAGS) $(CLUSSED_LIBS) $(CLUSSED_MODULES) $(CLUSSED_SLIBS) # uh. should set up some makedepend stuff soon. in the mean time... @@ -86,7 +86,7 @@ log.h csock.h cstring.h hmalloc.h cfg_iface.o: cfg_iface.h cfg_iface.c csock.h log.h hmalloc.h cstring.h \ af_inet.h af_ax25.h af_netrom.h -cfg_links.o: cfg_links.h cfg_links.c network.h hmalloc.h log.h +cfg_links.o: cfg_links.h cfg_links.c network.h hmalloc.h log.h timer.h config.h af_inet.o: af_inet.h af_inet.c csock.h log.h hmalloc.h config.h af_ax25.o: af_ax25.h af_ax25.c csock.h log.h hmalloc.h config.h af_netrom.o: af_netrom.h af_netrom.c csock.h log.h hmalloc.h @@ -98,26 +98,27 @@ main.o: ctime.h cstring.h log.h config.h csock.h timer.h version.h \ network.h cfile.h luser.o: luser.h luser.c config.h log.h hmalloc.h version.h csock.h \ - net_user.h f_luser.h + net_user.h f_luser.h timer.h ctime.h cluster.o: cluster.h cluster.c command.h help.h cmd_sys.h cmd_cluster.h \ - cmd_net.h cmd_usercfg.h network.h net_ping.h + cmd_net.h cmd_usercfg.h network.h net_ping.h luser.h command.o: command.h command.c csock.h cfgfile.h cmd_sys.o: cmd_sys.h cmd_sys.c csock.h version.h hmalloc.h cmd_cluster.o: cmd_cluster.h cmd_cluster.c csock.h hmalloc.h network.h \ cstring.h config.h net_user.h cfgfile.h -cmd_net.o: cmd_net.h cmd_net.c csock.h network.h net_user.h +cmd_net.o: cmd_net.h cmd_net.c csock.h network.h net_user.h ctime.h cmd_usercfg.o: cmd_usercfg.h cmd_usercfg.c csock.h luser.h cfgfile.h f_luser.h -help.o: help.h help.c csock.h +help.o: help.h help.c csock.h cluster.h network.o: network.h network.c net_ping.h net_link.h net_pc.h net_user.h \ net_rdb.h mid.h ctime.h config.h ctypes.h luser.h log.h \ crc.h hmalloc.h linker.h version.h cluster.h ui.h \ f_last.h f_nuser.h f_dx.h f_ann.h f_wwv.h timer.h net_link.o: net_link.h net_link.c network.h net_pc.h -net_pc.o: net_pc.h net_pc.c network.h log.h +net_pc.o: net_pc.h net_pc.c network.h net_user.h log.h cfgfile.h \ + hmalloc.h timer.h ctime.h net_ping.h net_user.o: net_user.h net_user.c network.h hmalloc.h log.h cluster.h \ - net_link.h f_nuser.h + net_link.h f_nuser.h timer.h net_ping.o: net_ping.h net_ping.c csock.h network.h luser.h cstring.h \ - ctime.h log.h + ctime.h log.h timer.h net_link.h config.h net_rdb.o: net_rdb.h net_rdb.c linker.o: linker.h linker.c hmalloc.h csock.h log.h cfgfile.h ui.o: ui.h ui.c diff -urN clussed-19981224/STRUCTURE clussed-19981227/STRUCTURE --- clussed-19981224/STRUCTURE Thu Jan 1 02:00:00 1970 +++ clussed-19981227/STRUCTURE Fri Dec 25 21:37:10 1998 @@ -0,0 +1,65 @@ + + This file tries to (sort of) document how messages and events are passed + through the code. It might eventually help someone find a place to stick + his/her own code in. + +Incoming connection: + + 1. csock.c: Noticed by select_loop lq (listen queue) check + which calls method lq->accept + 2. af_xxxx.c: xxxx_accept prepares the socket, calls sock_login + 3. csock.c: sock_login calls auth_login for authenticated listeners + (INET for the moment), luser_login for others + (auth_login calls luser_login) + 4. luser.c: luser_login either prepares the local user (and calls + lnuser_login), or calls link_login if the user appears to + be an incoming linker + +Incoming disconnection: + + 1: csock.c: Noticed by sock_read (returns EOF), select_loop calls + sock_close + 2: sock_close calls s->disc_handler + 3: disc_handler clears data structures for the user, link, whatever + 4: sock_close clears data structures for the socket + +Incoming data: + + 1: csock.c: Noticed by select_loop, calls sock_read to read data to + buffer and do optional decompression + 2: csock.c: select_loop calls sock_handle, which does optional + telnet negotiation, optional EOL searching for eol_text + sockets and calls s->in_handle method (which points to + luser_handler, pc_handler, etc) + +Outgoing data: + + 1: whatever calls csprintf, csputc, csputs, or something + 2: csock.c: csprintf calls csputs calls csputc + 3: cputc does optional EOL conversion, calls cswritec + 4: cswritec does optional telnet negotiation, calls csrwritec + 5: csrwritec stuffs the data to buffer, and if buffer is full, + csrwritec does optional compression and calls csrflush + to send the data. + 6: Else, the data is flushed when someone calls csflush(), which + does the optional compression and calls csrflush. + csflush() is called by csflush_all once every second + (off the timer). + +PC link message reception: + + 1: net_pc.c: pc_handler calls parse_pc to do the ^ argument parsing + and finds the correct handler method from the pcmds table, + calls the pc_NN handler + 2: net_pc.c: pc_NN handler parses the message, for messages + containing data allocates data structure and stuffs the + fields to the structure, calls the relevant net_XXX handler + 3: network.c: net_XXX inserts data to local memory structures + (and files), calls user_XXX to send the data to local users, + calls link_XXX to send the data to links + 4: cluster.c: user_XXX sends data to local users which are interested + in the data + 5: net_link.c: link_XXX calls pc_XXX to send the data to PC links + (will later call cll_XXX to send clulink messages too) + 6: net_pc.c: pc_XXX sends data to links using pc_send or pc_sendall + diff -urN clussed-19981224/af_ax25.c clussed-19981227/af_ax25.c --- clussed-19981224/af_ax25.c Thu Dec 24 17:55:05 1998 +++ clussed-19981227/af_ax25.c Thu Dec 24 20:43:59 1998 @@ -120,7 +120,7 @@ s->eol = AX25_EOL; s->call = hstrdup(ax2asc(&sockaddr.ax25.fsa_ax25.sax25_call)); - s->node = hstrdup(""); + s->node = NULL; addrlen = sizeof(struct full_sockaddr_ax25); getsockname(new_fd, (struct sockaddr *)&sockaddr, &addrlen); Binary files clussed-19981224/base/data/luser.db and clussed-19981227/base/data/luser.db differ diff -urN clussed-19981224/base/etc/links.conf clussed-19981227/base/etc/links.conf --- clussed-19981224/base/etc/links.conf Tue Dec 22 01:50:06 1998 +++ clussed-19981227/base/etc/links.conf Thu Dec 24 19:31:53 1998 @@ -1,13 +1,10 @@ -#link oh1rbi-1 +#link oh7lzb-1 #protocol pc -#script scripts/oh1rbi.con +#script scripts/oh7lzb-1.con -link oh7lzb-8 +link oh2lzb-1 protocol pc -script scripts/oh7lzb-8.con +mode incoming -#link oh7rba-1 -#protocol pc -#script scripts/oh7rba.con diff -urN clussed-19981224/base/scripts/oh7lzb-8.con~ clussed-19981227/base/scripts/oh7lzb-8.con~ --- clussed-19981224/base/scripts/oh7lzb-8.con~ Thu Dec 24 15:51:08 1998 +++ clussed-19981227/base/scripts/oh7lzb-8.con~ Thu Jan 1 02:00:00 1970 @@ -1,21 +0,0 @@ - -# -# Connection script for Clusse 0.40 -# - -#telnet localhost 3694 -#ax25 lo0 oh7lzb-2 -netrom nrcl oh7lzb-2 - -#s "c lo0 oh7lzb-2" -#r "connected" "disc" "fail" "err" - -#r "login:" -#s "oh7lzb-1" - -#r "Welcome" -#s "i" - -r "LinuxNode" -s "b" - Binary files clussed-19981224/base2/data/luser.db and clussed-19981227/base2/data/luser.db differ Binary files clussed-19981224/base2/data/nuser.db and clussed-19981227/base2/data/nuser.db differ diff -urN clussed-19981224/base2/etc/clussed.conf clussed-19981227/base2/etc/clussed.conf --- clussed-19981224/base2/etc/clussed.conf Thu Jan 1 02:00:00 1970 +++ clussed-19981227/base2/etc/clussed.conf Thu Dec 24 20:29:58 1998 @@ -0,0 +1,27 @@ + +# +# Visible hostname +# +HostName funk.oh7lzb.ampr.org + +# +# Cluster callsign +# +Callsign oh2lzb-1 + +# +# Sysop's callsign and name +# +SysopCall oh7lzb +SysopName Hessu + +# +# The QTH of the node (arbitrary string) +# +QTH Koivukylä, Vantaa + +# +# Date string field order: dmy, mdy, ymd or ydm +# +#DateFormat dmy + diff -urN clussed-19981224/base2/etc/interface.conf clussed-19981227/base2/etc/interface.conf --- clussed-19981224/base2/etc/interface.conf Thu Jan 1 02:00:00 1970 +++ clussed-19981227/base2/etc/interface.conf Thu Dec 24 20:30:52 1998 @@ -0,0 +1,36 @@ + +# +# TcpListen: Make clussed listen for connections on a TCP port +# +# TcpListen portname port (listen on all addresses) +# TcpListen portname host:port (listen on one address only) +# TcpListen portname ipaddr:port (without the help of DNS) +# +# The 'portname' is an arbitrary name string which Clusse will use +# in the user interface and logs for this interface. +# +# Feel free to use multiple TcpListen directives. +# + +TcpListen tcp 3692 + +# +# Ax25Listen: Make clussed listen for AX.25 connections +# +# Ax25Listen port:callsign (single callsign on a single port) +# Ax25Listen callsign (the same callsign on all ports) +# + +Ax25Listen oh2lzb-1 +Ax25Listen oh2lzb-7 compress +#Ax25Listen bpq:oh7lzb-2 + +# +# NetromListen: Make clussed listen for NET/ROM connections +# +# NetromListen port (port being defined in nrports) +# + +#NetromListen nrcl2 + + diff -urN clussed-19981224/base2/etc/links.conf clussed-19981227/base2/etc/links.conf --- clussed-19981224/base2/etc/links.conf Thu Jan 1 02:00:00 1970 +++ clussed-19981227/base2/etc/links.conf Thu Dec 24 20:31:11 1998 @@ -0,0 +1,10 @@ + +link oh7lzb-1 +protocol pc +script scripts/oh7lzb-1.con + +#link oh2lzb-1 +#protocol pc +#mode incoming + + diff -urN clussed-19981224/base2/scripts/oh1rbi.con clussed-19981227/base2/scripts/oh1rbi.con --- clussed-19981224/base2/scripts/oh1rbi.con Thu Jan 1 02:00:00 1970 +++ clussed-19981227/base2/scripts/oh1rbi.con Sun Dec 20 18:08:29 1998 @@ -0,0 +1,21 @@ + +# +# Connection script for Clusse 0.40 +# + +telnet localhost 3694 +# ax25 lo0 oh7lzb-2 +# netrom nrclu oh7lzb-2 + +#s "c lo0 oh7lzb-2" +#r "connected" "disc" "fail" "err" + +r "login:" +s "oh7lzb-1" + +r "Welcome" +s "i" + +r "LinuxNode" +s "b" + diff -urN clussed-19981224/base2/scripts/oh7lzb-1.con clussed-19981227/base2/scripts/oh7lzb-1.con --- clussed-19981224/base2/scripts/oh7lzb-1.con Thu Jan 1 02:00:00 1970 +++ clussed-19981227/base2/scripts/oh7lzb-1.con Sun Dec 27 02:55:07 1998 @@ -0,0 +1,22 @@ + +# +# Connection script for Clusse 0.40 +# + +#compressed +#telnet localhost 3694 +ax25 lo0 oh7lzb-1 +#netrom nrcl oh7lzb-2 + +#s "c lo0 oh7lzb-1" +#r "connected" "disc" "fail" "err" + +#r "login:" +#s "oh7lzb-1" + +#r "Welcome" +#s "i" + +#r "LinuxNode" +#s "b" + diff -urN clussed-19981224/cfg_links.c clussed-19981227/cfg_links.c --- clussed-19981224/cfg_links.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/cfg_links.c Sat Dec 26 01:49:08 1998 @@ -5,10 +5,15 @@ * links.conf directive parsing functions */ +#include +#include + #include "hmalloc.h" #include "network.h" #include "cfg_links.h" #include "log.h" +#include "timer.h" +#include "config.h" struct link_t *thislink = NULL; @@ -35,7 +40,7 @@ struct link_t *link; struct link_t *foo = *dest; - if (argc < 2) + if (argc != 2) return -1; link = hmalloc(sizeof(struct link_t)); @@ -53,6 +58,15 @@ strcpy(link->name, hstrupr(argv[1])); strcpy(link->call, argv[1]); + strcpy(link->mycall, (char *)clucall); + strcpy(link->link_call, (char *)clucall); + link->proto = lp_pc; + link->state = ls_disc; + link->since = now; + link->dreason = dr_unknown; + link->version = 0; + link->sock = NULL; + link->node = NULL; link_max++; @@ -83,6 +97,42 @@ int do_protocol(struct link_t **dest, int argc, char **argv) { + struct link_t *this = *dest; + + if (require_link(this) || (argc != 2)) + return -1; + + if (!strcasecmp(argv[1], "pc")) + this->proto = lp_pc; + else { + log(L_CRIT, "Unknown protocol: \"%s\"", argv[1]); + return -1; + } + + return 0; +} + +/* + * Mode + */ + +int do_mode(struct link_t **dest, int argc, char **argv) +{ + struct link_t *this = *dest; + int i; + + if (require_link(this) || (argc < 2)) + return -1; + + for (i = 1; i < argc; i++) { + if (!strcasecmp(argv[i], "incoming")) + this->mode = lm_incoming; + else { + log(L_CRIT, "Unknown mode: \"%s\"", argv[i]); + return -1; + } + } + return 0; } @@ -93,11 +143,22 @@ int do_script(struct link_t **dest, int argc, char **argv) { struct link_t *this = *dest; + char *s; + int i; if (require_link(this) || (argc < 2)) return -1; - - this->scripts = add_string(this->scripts, hstrdup(argv[1])); + + for (i = 1; i < argc; i++) { + if (*argv[i] == '/') + s = hstrdup(argv[i]); + else { + s = hmalloc(strlen(base_d) + strlen(argv[i]) + 1); + sprintf(s, "%s%s", base_d, argv[i]); + } + + this->scripts = add_string(this->scripts, s); + } return 0; } diff -urN clussed-19981224/cfg_links.h clussed-19981227/cfg_links.h --- clussed-19981224/cfg_links.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/cfg_links.h Thu Dec 24 19:38:29 1998 @@ -10,6 +10,7 @@ extern int do_destcall(struct link_t **dest, int argc, char **argv); extern int do_mycall(struct link_t **dest, int argc, char **argv); extern int do_protocol(struct link_t **dest, int argc, char **argv); +extern int do_mode(struct link_t **dest, int argc, char **argv); extern int do_script(struct link_t **dest, int argc, char **argv); #endif diff -urN clussed-19981224/cfgfile.c clussed-19981227/cfgfile.c --- clussed-19981224/cfgfile.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/cfgfile.c Fri Dec 25 00:40:51 1998 @@ -126,7 +126,7 @@ * Parse command line to argv, honoring quotes and such */ -int parse_args(char *argv[],char *cmd) +int parse_args(char *argv[], char *cmd) { int ct = 0; int quoted; diff -urN clussed-19981224/cfile.c clussed-19981227/cfile.c --- clussed-19981224/cfile.c Mon Dec 21 21:03:12 1998 +++ clussed-19981227/cfile.c Sat Dec 26 18:21:20 1998 @@ -21,3 +21,4 @@ close_luserf(); close_nuserf(); } + diff -urN clussed-19981224/cluster.c clussed-19981227/cluster.c --- clussed-19981224/cluster.c Mon Dec 21 20:24:08 1998 +++ clussed-19981227/cluster.c Sun Dec 27 04:29:55 1998 @@ -15,14 +15,18 @@ #include "cmd_usercfg.h" #include "network.h" #include "net_ping.h" +#include "luser.h" /* - * Configuration file commands + * Cluster commands */ struct cmd cluster_cmds[] = { { "bye", cmd_bye }, + { "commands", cmd_commands }, { "help", cmd_help }, + { "links", cmd_links }, + { "messages", cmd_messages }, { "memory", cmd_memory }, { "nodes", cmd_nodes }, { "name", cmd_name }, @@ -33,7 +37,7 @@ { "ping", cmd_ping }, { "pstatus", cmd_pstatus }, { "version", cmd_version }, - { "?", cmd_help }, + { "?", cmd_commands }, { "!", cmd_version }, { NULL, NULL, } }; @@ -53,34 +57,48 @@ void user_linkadd(struct link_t *l) { + send_us(M_LINK, "Linked to %s$t.", l->name); } void user_linkdel(struct link_t *l, char *reason) { + send_us(M_LINK, "Link to %s failed$t (%s).", l->name, reason); } void user_nodeadd(struct node_t *n) { + send_us(M_NODE, "Node %s added$t.", n->call); } void user_nodedel(struct node_t *n, char *reason) { + send_us(M_NODE, "Node %s vanished$t.", n->call); } void user_useradd(struct nuser_t *u) { + send_us((u->node == localnode) ? M_LUSER|M_NUSER : M_NUSER, + "User %s logged in$t.", u->call); } void user_userdel(struct nuser_t *u) { + send_us((u->node == localnode) ? M_LUSER|M_NUSER : M_NUSER, + "User %s logged out$t.", u->call); } void user_userhere(struct nuser_t *u) { + send_us((u->node == localnode) ? M_LUSER|M_NUSER : M_NUSER, + "User %s came back$t.", u->call); } void user_useraway(struct nuser_t *u) { + send_us((u->node == localnode) ? M_LUSER|M_NUSER : M_NUSER, + "User %s went away$t%s%s%s", u->call, + (u->away_str) ? ": " : ".", + (u->away_str) ? u->away_str : ""); } void user_dx(struct dx_t *dx) diff -urN clussed-19981224/cmd_cluster.c clussed-19981227/cmd_cluster.c --- clussed-19981224/cmd_cluster.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/cmd_cluster.c Sat Dec 26 03:45:41 1998 @@ -38,7 +38,7 @@ time(&t.time); hstrncpy(t.fromcall, s->lu->nu->call, sizeof(t.fromcall)); strcpy(t.fromnodec, (char *)clucall); - t.fromlink = NULL; + t.via = NULL; hstrupr(to); diff -urN clussed-19981224/cmd_net.c clussed-19981227/cmd_net.c --- clussed-19981224/cmd_net.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/cmd_net.c Sat Dec 26 18:41:35 1998 @@ -12,6 +12,7 @@ #include "cmd_net.h" #include "network.h" #include "net_user.h" +#include "ctime.h" /* * Node listing, with fancy 2-column display @@ -21,27 +22,34 @@ { static char s[40]; - sprintf(s, "%-10.10s", n->call); - if (n->via) - sprintf(s + strlen(s), "%-10.10s", n->via->call); - else - strcat(s, " "); + sprintf(s, "%-9.9s %-9.9s %c %-3d %-3d %-3.3s %-4d", + n->call, (n->via) ? n->via->call : "", + (n->here) ? 'H' : ' ', n->users, n->hops, + (n->rtt_ok) ? secs2str_s(n->rtt) : (n->pinging) ? "?" : "-", + n->version); return s; } int cmd_nodes(struct csock_t *s, int argc, char **argv) { - struct node_t *n1 = nodes, *n2 = nodes; + struct node_t *n1 = nodes, *n2 = nodes, *n2s; int i; - for (i = 0; i <= node_count/2; i++) + for (i = 0; i < node_count/2; i++) n2 = n2->next; /* Halfway up the list */ + if (i == 0) + n2 = n2->next; + + n2s = n2; - csprintf(s, "Nodes: %d (max %d), %d links\n", - node_count, node_max, link_count); - csputs(s, "Node Via Node Via\n"); - while (n1) { + csprintf(s, "Nodes: %d (max %d), %d of %d links\n", + node_count, node_max, link_count, link_max); + csputs(s, "Node Via H Usr Hop Rtt Ver"); + if (node_count > 1) + csputs(s, " Node Via H Usr Hop Rtt Ver"); + csputs(s, "\n"); + while (n1 && n1 != n2s) { csputs(s, nodestr(n1)); if (n2) { csputc(s, ' '); @@ -54,6 +62,79 @@ return 0; } + +/* + * Link listing + */ + +char *lm_str(enum linkmode_t lm) +{ + static char s[7]; + + switch (lm) { + case lm_normal: + sprintf(s, "Normal"); + break; + case lm_incoming: + sprintf(s, "In"); + break; + case lm_listen: + sprintf(s, "Listen"); + break; + default: + sprintf(s, "?!?"); + break; + } + + return s; +} + +char *ls_str(enum linkstate_t ls) +{ + static char s[7]; + + switch (ls) { + case ls_disc: + sprintf(s, "Disc"); + break; + case ls_init: + sprintf(s, "Init"); + break; + case ls_linked: + sprintf(s, "Linked"); + break; + case ls_backup: + sprintf(s, "Backup"); + break; + case ls_held: + sprintf(s, "Held"); + break; + default: + sprintf(s, "?!?"); + break; + } + + return s; +} + +int cmd_links(struct csock_t *s, int argc, char **argv) +{ + struct link_t *l; + + csprintf(s, "Links: %d of %d up\n", + link_count, link_max); + csputs(s, "Link Mode State Ver fd\n"); + for (l = links; (l); l = l->next) { + csprintf(s, "%-9.9s %-6.6s %-6.6s %-4d %d\n", + l->name, lm_str(l->mode), ls_str(l->state), l->version, + l->sock ? l->sock->fd : 0); + } + + return 0; +} + + + /* * User listing diff -urN clussed-19981224/cmd_net.h clussed-19981227/cmd_net.h --- clussed-19981224/cmd_net.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/cmd_net.h Thu Dec 24 19:43:07 1998 @@ -5,6 +5,7 @@ #include "csock.h" extern int cmd_nodes(struct csock_t *s, int argc, char **argv); +extern int cmd_links(struct csock_t *s, int argc, char **argv); extern int cmd_users(struct csock_t *s, int argc, char **argv); #endif diff -urN clussed-19981224/cmd_sys.c clussed-19981227/cmd_sys.c --- clussed-19981224/cmd_sys.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/cmd_sys.c Fri Dec 25 22:57:34 1998 @@ -59,7 +59,9 @@ for (p = sockets; (p); p = p->next) { csprintf(s, "%-3d %c %c %-9.9s %-15.15s %-5.5s %s", p->fd, cst2chr(p->type), css2chr(p->state), - p->call, p->node, p->port, + (p->call) ? p->call : "?", + (p->node) ? p->node : "-", + (p->port) ? p->port : "?", bytes2str(p->in_count)); csprintf(s, " %s", bytes2str(p->out_count)); csprintf(s, " %s", bytes2str(p->ibuf.pos)); diff -urN clussed-19981224/cmd_usercfg.c clussed-19981227/cmd_usercfg.c --- clussed-19981224/cmd_usercfg.c Mon Dec 21 20:39:09 1998 +++ clussed-19981227/cmd_usercfg.c Sun Dec 27 04:21:41 1998 @@ -13,6 +13,10 @@ #include "cfgfile.h" #include "f_luser.h" +/* + * View or change name + */ + int cmd_name(struct csock_t *s, int argc, char **argv) { if (argc > 1) { @@ -26,6 +30,79 @@ csprintf(s, "Your name is set to: %s\n", s->lu->f->name); else csputs(s, "Your name is not set.\n"); + + return 0; +} + +/* + * View or change messages + */ + +int cmd_messages(struct csock_t *s, int argc, char **argv) +{ + int setto = 1; + int i; + char *p; + unsigned long *m = &s->lu->f->messages; + + for (i = 1; i < argc; i++) { + for (p = argv[i]; (*p); p++) { + switch (*p) { + case '+': + setto = 1; + break; + case '-': + setto = 0; + break; + case 'd': + if (setto) *m |= M_DX; + else *m &= ~M_DX; + break; + case 'a': + if (setto) *m |= M_ANN; + else *m &= ~M_ANN; + break; + case 'w': + if (setto) *m |= M_WWV; + else *m &= ~M_WWV; + break; + case 't': + if (setto) *m |= M_TALK; + else *m &= ~M_TALK; + break; + case 'u': + if (setto) *m |= M_NUSER; + else *m &= ~M_NUSER; + break; + case 'l': + if (setto) *m |= M_LUSER; + else *m &= ~M_LUSER; + break; + case 'i': + if (setto) *m |= M_LINK; + else *m &= ~M_LINK; + break; + case 'n': + if (setto) *m |= M_NODE; + else *m &= ~M_NODE; + break; + } + } + } + + if (argc > 1) + write_luserf(s->lu->f); + + csputs(s, "Messages:\n"); + if (*m & M_DX) csputs(s, " Dx"); + if (*m & M_ANN) csputs(s, " Announce"); + if (*m & M_WWV) csputs(s, " Wwv"); + if (*m & M_TALK) csputs(s, " Talk"); + if (*m & M_NUSER) csputs(s, " User"); + if (*m & M_LUSER) csputs(s, " Localuser"); + if (*m & M_LINK) csputs(s, " lInk"); + if (*m & M_NODE) csputs(s, " Node"); + csputc(s, '\n'); return 0; } diff -urN clussed-19981224/cmd_usercfg.h clussed-19981227/cmd_usercfg.h --- clussed-19981224/cmd_usercfg.h Mon Dec 21 20:09:00 1998 +++ clussed-19981227/cmd_usercfg.h Sun Dec 27 04:00:24 1998 @@ -5,5 +5,6 @@ #include "csock.h" extern int cmd_name(struct csock_t *s, int argc, char **argv); +extern int cmd_messages(struct csock_t *s, int argc, char **argv); #endif diff -urN clussed-19981224/config.c clussed-19981227/config.c --- clussed-19981224/config.c Thu Dec 24 16:50:59 1998 +++ clussed-19981227/config.c Thu Dec 24 20:37:26 1998 @@ -8,6 +8,7 @@ #include #include #include +#include #include "config.h" #include "ctypes.h" @@ -54,6 +55,7 @@ { "mycall", _CFUNC_ do_mycall, &thislink }, { "protocol", _CFUNC_ do_protocol, &thislink }, { "script", _CFUNC_ do_script, &thislink }, + { "mode", _CFUNC_ do_mode, &thislink }, { NULL, NULL, NULL } }; diff -urN clussed-19981224/csock.c clussed-19981227/csock.c --- clussed-19981224/csock.c Tue Dec 22 12:50:29 1998 +++ clussed-19981227/csock.c Sat Dec 26 02:22:13 1998 @@ -215,10 +215,10 @@ (c->zin.total_out + c->zout.total_in == 0) ? 0.0 : ( (double)c->zin.total_in + (double)c->zout.total_out ) / (c->zin.total_out + c->zout.total_in)); - if ((i = deflateEnd(&c->zout)) != Z_OK) + if ((i = deflateEnd(&c->zout)) != Z_OK && (c->zout.msg)) log(L_ERR, "fd %d: deflateEnd returned %d: %s", s->fd, i, c->zout.msg); - if ((i = inflateEnd(&c->zout)) != Z_OK) + if ((i = inflateEnd(&c->zout)) != Z_OK && (c->zout.msg)) log(L_ERR, "fd %d: inflateEnd returned %d: %s", s->fd, i, c->zout.msg); hfree(s->ribuf->buf); @@ -242,7 +242,7 @@ * Create an outgoing connection */ -struct csock_t *sock_connect(int af_type, int argc, char **argv) +struct csock_t *sock_connect(int af_type, int compressed, int argc, char **argv) { struct csock_t *s = NULL; @@ -274,7 +274,7 @@ goto trouble; } - if (!(s = sock_alloc(fd, af_type, DEF_BUFLEN_IN, 80, 0))) + if (!(s = sock_alloc(fd, af_type, DEF_BUFLEN_IN, 80, compressed))) goto trouble; memset(&s->sockaddr, 0, sizeof(s->sockaddr)); @@ -316,7 +316,7 @@ goto trouble; } - if (!(s = sock_alloc(fd, af_type, DEF_BUFLEN_AX, 80, 0))) + if (!(s = sock_alloc(fd, af_type, DEF_BUFLEN_AX, 80, compressed))) goto trouble; for (i = 1; i < argc; i++) @@ -335,7 +335,7 @@ goto trouble; } - if (!(s = sock_alloc(fd, af_type, DEF_BUFLEN_NR, 80, 0))) + if (!(s = sock_alloc(fd, af_type, DEF_BUFLEN_NR, 80, compressed))) goto trouble; for (i = 1; i < argc; i++) @@ -927,7 +927,7 @@ if (s->af_type == AF_INET) auth_login(s); - else /* For now, only lusers allowed.... */ + else luser_login(s); } diff -urN clussed-19981224/csock.h clussed-19981227/csock.h --- clussed-19981224/csock.h Thu Dec 24 16:59:52 1998 +++ clussed-19981227/csock.h Sat Dec 26 02:16:50 1998 @@ -185,7 +185,7 @@ int obuf_tresh, int compressed); extern void sock_login(struct csock_t *s); extern void sock_disconnect(struct csock_t *s); -extern struct csock_t *sock_connect(int af_type, int argc, char **argv); +extern struct csock_t *sock_connect(int af_type, int compressed, int argc, char **argv); /* Socket output */ extern int csflush(struct csock_t *s); /* Flush a socket */ diff -urN clussed-19981224/ctime.c clussed-19981227/ctime.c --- clussed-19981224/ctime.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/ctime.c Sat Dec 26 03:37:34 1998 @@ -59,7 +59,7 @@ * Seconds => d hh:mm:ss */ -char *secs2str(long i) +char *secs2str_l(long i) { static char s[40]; int sec, min, hou; @@ -121,7 +121,7 @@ * Minutes => d hh:mm */ -char *mins2str(long i) +char *mins2str_l(long i) { /* minutes => d hh:mm */ static char s[10]; @@ -317,5 +317,32 @@ sprintf(s, "%2.2d%2.2d", tm->tm_hour, tm->tm_min); return s; +} + +/* + * PC string to time_t + */ + +extern time_t pcstr2t(char *pcdate, char *pctime) +{ + return 0; +} + +/* + * time_t to PC date + */ + +extern char *pcdatestr(time_t t) +{ + return NULL; +} + +/* + * time_t to PC time + */ + +extern char *pctimestr(time_t t) +{ + return NULL; } diff -urN clussed-19981224/ctime.h clussed-19981227/ctime.h --- clussed-19981224/ctime.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/ctime.h Sat Dec 26 03:37:20 1998 @@ -14,11 +14,11 @@ extern void ctime_init(void); /* Initialize */ extern long int uptime(void); /* Clusse uptime */ -extern char *secs2str(long i); /* Seconds => d hh:mm:ss */ +extern char *secs2str_l(long i); /* Seconds => d hh:mm:ss */ extern char *secs2str_s(long i); /* Seconds => d/h/m/s 3 chars */ -extern char *mins2str(long i); /* Minutes => d hh:mm */ +extern char *mins2str_l(long i); /* Minutes => d hh:mm */ extern char *mins2str_s(long i); /* Minutes => d/h/m 3 chars */ -extern char *datestr(time_t t); /* Packed => 01/10/77 */ +extern char *datestr_l(time_t t); /* Packed => 01/10/77 */ extern char *datestr_s(time_t t); /* Packed => '1/1' */ extern char *datestr_s_pad(time_t t); /* Packed => ' 1/1 ' (5chars) */ extern char *timestr_l(time_t t); /* Packed => 02:30:12 */ @@ -27,5 +27,9 @@ extern char *timestr_s(time_t t); /* Packed => 0230 */ extern char *datetimestr(time_t t); /* Day, date, time */ extern char *tz2str(double tz); /* Timezone to a string */ + +extern time_t pcstr2t(char *pcdate, char *pctime); /* PC string to time_t */ +extern char *pcdatestr(time_t t); /* time_t to PC date */ +extern char *pctimestr(time_t t); /* time_t to PC time */ #endif diff -urN clussed-19981224/help.c clussed-19981227/help.c --- clussed-19981224/help.c Tue Dec 22 12:48:22 1998 +++ clussed-19981227/help.c Sat Dec 26 18:18:03 1998 @@ -1,6 +1,19 @@ #include "csock.h" +#include "cluster.h" #include "help.h" + +int cmd_commands(struct csock_t *s, int argc, char **argv) +{ + struct cmd *c; + + csputs(s, "Commands:\n"); + for (c = cluster_cmds; c->function != NULL; c++) + csprintf(s, " %s", c->name); + csputs(s, "\n"); + + return 0; +} int cmd_help(struct csock_t *s, int argc, char **argv) { diff -urN clussed-19981224/help.h clussed-19981227/help.h --- clussed-19981224/help.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/help.h Sat Dec 26 18:18:20 1998 @@ -4,6 +4,7 @@ #include "csock.h" +extern int cmd_commands(struct csock_t *s, int argc, char **argv); extern int cmd_help(struct csock_t *s, int argc, char **argv); #endif diff -urN clussed-19981224/linker.c clussed-19981227/linker.c --- clussed-19981224/linker.c Tue Dec 22 03:19:32 1998 +++ clussed-19981227/linker.c Sat Dec 26 02:28:52 1998 @@ -110,10 +110,8 @@ { struct linkjob_t *lj; - if (!(lj = lj_find(s))) { - log(L_ERR, "done_connect(): no job for the stream!"); + if (!(lj = lj_find(s))) return; - } end_connect(lj, 0); } @@ -247,6 +245,7 @@ { struct linkjob_t *lj; int af_type; + int compressed = 0; lj = lj_alloc(); lj->linec = 0; @@ -268,13 +267,23 @@ return 0; } + if (!strcasecmp(lj->argv[0], "compressed")) { + compressed = 1; + if (read_scriptline(lj)) { + log(L_ERR, "Linker: No connection command after \"compressed\" in %s", + lj->script); + lj_free(lj); + return 0; + } + } + if ((af_type = strtoaf(lj->argv[0])) == -1) { log(L_ERR, "Linker: Unknown AF type %s, confusing.", lj->argv[0]); lj_free(lj); return 0; } - lj->s = sock_connect(af_type, lj->argc-1, &lj->argv[1]); + lj->s = sock_connect(af_type, compressed, lj->argc-1, &lj->argv[1]); if (!lj->s) { log(L_ERR, "Linker: sock_connect() failed"); diff -urN clussed-19981224/log.h clussed-19981227/log.h --- clussed-19981224/log.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/log.h Sat Dec 26 19:52:50 1998 @@ -25,7 +25,7 @@ #define L_SINFO 524288 /* Socket information (bindings, connections) */ #define L_COMPR 1048576 /* Compression details (rates, etc) */ -#define L_DEFLEVEL (L_ERR | L_R_ERR | L_LINK | L_LUSER | L_CRIT | L_INFO | L_SECURITY | L_SINFO | L_DEBUG | L_COMPR) +#define L_DEFLEVEL (L_ERR | L_R_ERR | L_LINK | L_NODE | L_NUSER | L_LUSER | L_PING | L_CRIT | L_INFO | L_SECURITY | L_SINFO | L_DEBUG | L_COMPR) #define L_STDERR 1 /* Log to stderror */ #define L_SYSLOG 2 /* Log to syslog */ diff -urN clussed-19981224/luser.c clussed-19981227/luser.c --- clussed-19981224/luser.c Thu Dec 24 15:55:26 1998 +++ clussed-19981227/luser.c Sun Dec 27 03:58:06 1998 @@ -9,6 +9,7 @@ #include #include #include +#include #include "config.h" #include "csock.h" @@ -19,6 +20,8 @@ #include "hmalloc.h" #include "net_user.h" #include "f_luser.h" +#include "timer.h" +#include "ctime.h" struct luser_t *lusers = NULL; @@ -110,16 +113,57 @@ * Send a message to lusers who are interested in it */ -int send_us(int mtype, int mflag, char *s) +int send_us(int mtype, char *fmt, ...) { struct luser_t *p; int i = 0; + va_list args; + char str[MAX_SENDLEN+1]; + char str_t[MAX_SENDLEN+1]; + char *cp, *ct; + + cp = fmt; + ct = str; + while (*cp) { + if (*cp == '$') { + cp++; + switch (*cp) { + case 't': + *ct++ = ' '; + strcpy(ct, timestr_s(now)); + ct += 4; + *ct++ = 'Z'; + break; + case '\0': + cp--; + break; + default: + *ct++ = '$'; + } + } else { + *ct++ = *cp; + } + cp++; + } + *ct++ = '\0'; + + va_start(args, fmt); + vsnprintf(str_t, MAX_SENDLEN, str, args); + va_end(args); + + va_start(args, fmt); + vsnprintf(str, MAX_SENDLEN, fmt, args); + va_end(args); + + str[MAX_SENDLEN] = '\0'; for (p = lusers; (p); p = p->next) { - if (((p->f->messages & mtype) == mtype) - && ((p->f->flags & F_TIMESTAMP) == mflag)) { + if ((p->f->messages & mtype) == mtype) { i++; - csputs(p->sock, s); + if (p->f->flags & F_TIMESTAMP) + csputs(p->sock, str_t); + else + csputs(p->sock, str); if (((p->f->flags & F_BEEPS) == F_BEEPS) /* Licence */ && ((p->f->beeps & mtype) == mtype)) /* to kill? */ csputc(p->sock, '\007'); @@ -195,18 +239,31 @@ { struct luser_t *lu; int newuser = 0; + struct link_t *li; + call_t *ncall; - log(L_LUSER, "User: %s@%s:%s logged in", s->call, s->node, s->port); + if (getssid((call_t *)s->call) == 0) + truncssid((call_t *)s->call); + + if ((li = get_link((call_t *)s->call)) && li->mode == lm_incoming) { + link_login(s, li); + return; + } lu = luser_alloc(s); lu->f = read_luserf((call_t *)s->call); if (!lu->f) { newuser = 1; - log(L_LUSER, "User: %s is a new user, creating", s->call); + log(L_LUSER, "Local: %s is a new user, creating", s->call); lu->f = new_luserf(s->call); write_luserf(lu->f); } - lu->nu = nuser_login(NULL, select_nucall(s->call), localnode, 1); + + ncall = select_nucall(lu->f->call); + strcpy(lu->f->call, (char *)ncall); + + log(L_LUSER, "Local: %s logged in", lu->f->call); + lu->nu = lnuser_login(lu); /* OH7LZB Clusse v0.31 - DX Cluster node OH7RBA-1 - 54/6 users, 16/2 nodes */ csprintf(s, "%s - DX Cluster node %s\n", SOFT_STRING, clucall); @@ -225,8 +282,8 @@ void luser_logout(struct csock_t *s) { - log(L_LUSER, "User: %s@%s:%s logged out", s->call, s->node, s->port); - net_deluser(NULL, s->lu->nu); + log(L_LUSER, "Local: %s logged out", s->lu->f->call); + net_userdel(s->lu->nu); luser_free(s->lu); } diff -urN clussed-19981224/luser.h clussed-19981227/luser.h --- clussed-19981224/luser.h Mon Dec 21 20:16:05 1998 +++ clussed-19981227/luser.h Sun Dec 27 03:24:07 1998 @@ -88,7 +88,7 @@ extern struct luser_t *get_luser(call_t *call); -extern int send_us(int mtype, int mflag, char *s); +extern int send_us(int mtype, char *fmt, ...); extern void luser_login(struct csock_t *s); extern void luser_logout(struct csock_t *s); diff -urN clussed-19981224/net_link.c clussed-19981227/net_link.c --- clussed-19981224/net_link.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_link.c Sat Dec 26 19:03:22 1998 @@ -13,35 +13,53 @@ #include "net_pc.h" /* - * Node deletion + * Beacon */ -void link_nodedel(struct node_t *n, char *reason) +void link_beacon(struct link_t *l) { + pc_beacon(l); } /* - * Cluster events + * Send a ping */ -void link_dx(struct dx_t *dx) +void link_ping(struct link_t *l, call_t *to, call_t *from, int flag) { - pc_dx(dx); + pc_ping(l, to, from, flag); } -void link_announce(struct ann_t *ann) +/* + * Request link closing + */ + +void link_reqclose(struct link_t *l, char *reason) { - pc_announce(ann); + pc_reqclose(l, reason); } -void link_wwv(struct wwv_t *wwv) +/* + * Nodes + */ + +void link_nodeadd(struct node_t *n) { - pc_wwv(wwv); + pc_nodeadd(n); } -void link_talk(struct talk_t *talk) +void link_nodedel(struct node_t *n, char *reason) { - pc_talk(talk); + pc_nodedel(n, reason); +} + +/* + * Users + */ + +void link_useradd(struct nuser_t *nu) +{ + pc_useradd(nu); } void link_userdel(struct nuser_t *nu) @@ -57,5 +75,29 @@ void link_userhere(struct nuser_t *nu) { pc_userhere(nu); +} + +/* + * Cluster events + */ + +void link_dx(struct dx_t *dx) +{ + pc_dx(dx); +} + +void link_announce(struct ann_t *ann) +{ + pc_announce(ann); +} + +void link_wwv(struct wwv_t *wwv) +{ + pc_wwv(wwv); +} + +void link_talk(struct talk_t *talk) +{ + pc_talk(talk); } diff -urN clussed-19981224/net_link.h clussed-19981227/net_link.h --- clussed-19981224/net_link.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_link.h Sat Dec 26 19:03:12 1998 @@ -4,14 +4,22 @@ #include "network.h" +extern void link_beacon(struct link_t *l); +extern void link_ping(struct link_t *l, call_t *to, call_t *from, int flag); +extern void link_reqclose(struct link_t *l, char *reason); + +extern void link_nodeadd(struct node_t *n); extern void link_nodedel(struct node_t *n, char *reason); + +extern void link_useradd(struct nuser_t *nu); +extern void link_userdel(struct nuser_t *nu); +extern void link_useraway(struct nuser_t *nu); +extern void link_userhere(struct nuser_t *nu); + extern void link_dx(struct dx_t *dx); extern void link_announce(struct ann_t *ann); extern void link_wwv(struct wwv_t *wwv); extern void link_talk(struct talk_t *t); -extern void link_userdel(struct nuser_t *nu); -extern void link_useraway(struct nuser_t *nu); -extern void link_userhere(struct nuser_t *nu); #endif diff -urN clussed-19981224/net_pc.c clussed-19981227/net_pc.c --- clussed-19981224/net_pc.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_pc.c Sat Dec 26 19:51:45 1998 @@ -6,101 +6,423 @@ */ #include +#include +#include +#include #include "net_pc.h" #include "network.h" +#include "net_user.h" +#include "net_ping.h" #include "log.h" +#include "cfgfile.h" +#include "hmalloc.h" +#include "timer.h" +#include "ctime.h" + +int pc_10(struct link_t *l, int argc, char **argv); +int pc_11(struct link_t *l, int argc, char **argv); +int pc_12(struct link_t *l, int argc, char **argv); +int pc_16(struct link_t *l, int argc, char **argv); +int pc_17(struct link_t *l, int argc, char **argv); +int pc_18(struct link_t *l, int argc, char **argv); +int pc_19(struct link_t *l, int argc, char **argv); +int pc_20(struct link_t *l, int argc, char **argv); +int pc_21(struct link_t *l, int argc, char **argv); +int pc_22(struct link_t *l, int argc, char **argv); +int pc_23(struct link_t *l, int argc, char **argv); +int pc_38(struct link_t *l, int argc, char **argv); +int pc_50(struct link_t *l, int argc, char **argv); +int pc_51(struct link_t *l, int argc, char **argv); + +struct pcmd pcmds[] = { + { 10, pc_10 }, + { 11, pc_11 }, + { 12, pc_12 }, + { 16, pc_16 }, + { 17, pc_17 }, + { 18, pc_18 }, + { 19, pc_19 }, + { 20, pc_20 }, + { 21, pc_21 }, + { 22, pc_22 }, + { 23, pc_23 }, + { 38, pc_38 }, + { 50, pc_50 }, + { 51, pc_51 }, + { 0, NULL } +}; int pc_msgstats[51]; +/* + * Convert PC hop counters + */ + char *hops2pcstr(int hops) { static char s[6]; - snprintf(s, 3, "H%d", hops); - s[3] = '\0'; + snprintf(s, 4, "H%d", 99 - hops); + s[4] = '\0'; return s; } +int pchops2int(char *s) +{ + int i; + + if (*s != 'H') + return 99; + s++; + if (!*s) + return 99; + i = atoi(s); + if ((i > 99) || (i < 1)) + return 99; + + return 100 - i; +} + /* - * Send message to all PC links, except for the one it came from + * Send message to a PC link */ -void pc_sendall(struct link_t *via, char *fmt, ...) +int pc_send(struct link_t *via, const char *fmt, ...) { + char s[PCMAXLEN+1]; + va_list args; + + va_start(args, fmt); + vsnprintf(s, PCMAXLEN, fmt, args); + va_end(args); + + return csputs(via->sock, s); } /* - * Handshaking + * Send message to all PC links, except for the one it came from */ -void pc_sendloopcheck(struct link_t *l) +int pc_sendall(struct link_t *via, const char *fmt, ...) { + struct link_t *l; + int i = 0; + char s[PCMAXLEN+1]; + va_list args; + + va_start(args, fmt); + vsnprintf(s, PCMAXLEN, fmt, args); + va_end(args); + + for (l = links; (l); l = l->next) + if (l != via && l->proto == lp_pc && l->state == ls_linked) { + csputs(l->sock, s); + i++; + } + + return i; } -void pc_sendcluid(struct link_t *l) +/* + * Beacon + */ + +void pc_beacon(struct link_t *l) { + pc_send(l, "PC50^%s^%d^%s^\n", l->mycall, luser_count, hops2pcstr(0)); } -void pc_handshake(struct link_t *l) +/* + * Send a ping + */ + +void pc_ping(struct link_t *l, call_t *to, call_t *from, int flag) { + pc_send(l, "PC51^%s^%s^%d^\n", to, from, flag); + csflush(l->sock); } +/* + * Request link closing + */ + +void pc_reqclose(struct link_t *l, char *reason) +{ + pc_send(l, "PC39^%s^%s^\n", l->mycall, reason); + csflush(l->sock); +} /* - * Node deletion + * Send full node list in sane order */ -void pc_nodedel(struct node_t *n, char *reason) +char *add_node_str(char *s, struct node_t *n) { + n->locked = 1; + sprintf(s, "^%c^%s^0^%d", (n->here) ? '1' : '0', n->call, n->version); + return s; +} + +void pc_sendnodes(struct link_t *l, struct node_t *n) +{ + struct node_t *p; + char s[PCMAXLEN]; + int i; + int chosen; + + clear_nlocks(); + pc_send(l, "PC19^0^%s^0^%d^H99^\n", l->mycall, pc_version); + while (1) { + strcpy(s, "PC19"); + i = 0; + chosen = 0; + p = n; + while (p) { + if ((chosen && p->via != l && p->hops_ok && p->hops == chosen && !p->locked) + || (!chosen && p->via != l && p->hops_ok && !p->locked && p->hops < 99 && p->hops > 0)) { + if (!chosen) + chosen = p->hops; + add_node_str(s + strlen(s), p); + i++; + } + if (strlen(s) > PCMAXLEN - 30 || (!p->next && (i))) { + sprintf(s + strlen(s), "^%s\n", hops2pcstr(chosen)); + pc_send(l, "%s", s); + i = 0; + strcpy(s, "PC19"); + } + p = p->next; + } + if (!chosen) + return; + } + } /* - * Cluster events + * Node list */ -void pc_dx(struct dx_t *dx) +void pc_nodeadd(struct node_t *n) { + struct link_t *l; + + for (l = links; (l); l = l->next) + if (l != n->via && l->proto == lp_pc && l->state == ls_linked) + pc_sendnodes(l, n); } -void pc_announce(struct ann_t *ann) +void pc_nodedel(struct node_t *n, char *reason) { + if (n->hops <= 98) + pc_send(n->via, "PC21^%s^%s^%s^\n", n->call, reason, hops2pcstr(n->hops)); } -void pc_wwv(struct wwv_t *wwv) +/* + * User list + */ + + +/* + * Send a list of users + */ + +void pc_sendusers(struct link_t *l, struct nuser_t *nu) { + struct nuser_t *p; + struct node_t *n; + char s[PCMAXLEN]; + int i; + + for (n = nodes; (n); n = n->next) { + sprintf(s, "PC16^%s", n->call); + i = 0; + + p = nu; + while (p) { + if (p->node == n) { + sprintf(s + strlen(s), "^%s %c %c", p->call, '-', (p->here) ? '1' : '0'); + i++; + } + if (strlen(s) > PCMAXLEN - 30 || (!p->next && (i))) { + sprintf(s + strlen(s), "^%s^\n", hops2pcstr(n->hops)); + pc_send(l, "%s", s); + i = 0; + sprintf(s, "PC16^%s", n->call); + } + p = p->next; + } + } } -void pc_talk(struct talk_t *talk) +void pc_useradd(struct nuser_t *nu) { + struct link_t *l; + + for (l = links; (l); l = l->next) + if (l != nu->node->via && l->proto == lp_pc && l->state == ls_linked) + pc_sendusers(l, nu); } void pc_userdel(struct nuser_t *nu) { - if (pc_hops <= 98) - pc_sendall(nu->node->via, "PC17^%s^%s^%s^\n", nu->call, nu->node->call, hops2pcstr(pc_hops)); + if (nu->hops <= 98) + pc_sendall(nu->node->via, "PC17^%s^%s^%s^\n", nu->call, nu->node->call, hops2pcstr(nu->hops)); } void pc_useraway(struct nuser_t *nu) { - if (nu->here && nu->node->hops <= 98) { + if (nu->here && nu->hops <= 98) { /* Only send PC24 if the user did go away for the first time. Changing the away string doesn"t affect the PC. */ - pc_sendall(nu->node->via, "PC24^%s^0^%s^\n", nu->call, hops2pcstr(pc_hops)); + pc_sendall(nu->node->via, "PC24^%s^0^%s^\n", nu->call, hops2pcstr(nu->hops)); } } void pc_userhere(struct nuser_t *nu) { - if (pc_hops <= 98) - pc_sendall(nu->node->via, "PC24^%s^1^%s^\n", nu->call, hops2pcstr(pc_hops)); + if (nu->hops <= 98) + pc_sendall(nu->node->via, "PC24^%s^1^%s^\n", nu->call, hops2pcstr(nu->hops)); return; } /* + * Cluster events + */ + +void pc_dx(struct dx_t *dx) +{ + if (dx->hops <= 98) + pc_sendall(dx->via, "PC11^%s^%s^%s^%s^%s^%s^%s^%s^~\n", + freq2str(dx->freq), dx->call, pcdatestr(dx->time), + pctimestr(dx->time), dx->info, dx->fromcall, dx->fromnodec, hops2pcstr(dx->hops)); +} + +void pc_announce(struct ann_t *ann) +{ + int c = '\0'; + if (strlen(ann->message) > 190) { + c = ann->message[189]; + ann->message[189] = '\0'; + } + + if (ann->hops <= 98) + pc_sendall(ann->via, "PC12^%s^%s^%s^%s^%s^%s^%s^~\n", + ann->fromcall, ann->tonodec, + (*ann->message) ? ann->message : " ", + (ann->sysop) ? "*" : " ", ann->fromnodec, + (ann->wx) ? "1" : "0", hops2pcstr(ann->hops)); + + if (c) + ann->message[189] = c; +} + +void pc_wwv(struct wwv_t *wwv) +{ + if (wwv->hops <= 98) + pc_sendall(wwv->via, "PC23^%s^%d^%d^%d^%d^%s^%s^%s^%s^~\n", + pcdatestr(wwv->time), wwv->hour, wwv->sfi, wwv->a, + wwv->k, + (*wwv->forecast) ? wwv->forecast : " ", + wwv->fromcall, wwv->fromnodec, + hops2pcstr(wwv->hops)); +} + +void pc_talk(struct talk_t *talk) +{ + struct nuser_t *nu; + struct node_t *n; + + nu = get_nuser(&talk->tocall); + n = get_node(&talk->tocall); + + pc_send(talk->tonode->via, "PC10^%s^%s^%s^%c^%s^%s^~\n", + talk->fromcall, + (nu) ? talk->tocall : talk->tonode->call, + (*talk->message) ? talk->message : " ", + '*', + ((nu) || (n)) ? " " : talk->tocall, + talk->fromnodec); +} + +/* + * PC ^ line parsing + */ + +int parse_pc(char *argv[], char *cmd) +{ + int ct = 0; + + while (ct < 255) + { + if (*cmd == 0) + break; + argv[ct++] = cmd; + while (*cmd && *cmd != '^') + cmd++; + if (*cmd) + *cmd++ = 0; + } + argv[ct] = NULL; + return ct; +} + +/* + * Bad amount of arguments received + */ + +int invalid_argc(struct link_t *l, int wanted, int argc, char **argv) +{ + log(L_ERR, "PC: %s: Got %d args, expected %d: %s", + l->name, argc, wanted, argstr(0, argc, argv)); + return 0; +} + +/* + * Handshaking + */ + +void pc_sendloopcheck(struct link_t *l) +{ + struct node_t *n; + char s[PCMAXLEN+1]; + int i = 1; + + sprintf(s, "PC38^%s", localnode->call); + for (n = nodes; (n); n = n->next) { + if (n != localnode) { + i++; + if (i > 1) + strcat(s, ","); + strcat(s, n->call); + } + if (strlen(s) > PCMAXLEN-20 || n->next == NULL) { + strcat(s, "^~\n"); + pc_send(l, "%s", s); + sprintf(s, "PC38^"); + i = 0; + } + } +} + +void pc_sendcluid(struct link_t *l) +{ + pc_send(l, "PC18^%s^%d^~\n", SOFT_STRING, pc_version); +} + +void pc_conn_handler(struct link_t *l) +{ + log(L_LINK, "PC: %s: Incoming connection, requesting initialisation", + l->name); + pc_sendloopcheck(l); + pc_sendcluid(l); +} + +/* * Disconnection handler */ @@ -119,7 +441,336 @@ int pc_handler(struct csock_t *s, void *data, int len) { char *p = (char *)data; + int argc; + char *argv[256]; + int cmdid = 50; + struct pcmd *cmdp; + + if ((argc = parse_pc(argv, p)) == 0 || *argv[0] == '#') + return 0; + + if (strstr(argv[0], "PC") != argv[0] || strlen(argv[0]) != 4) + return 0; + + p = argv[0] + 2; + cmdid = atoi(p); + if (cmdid < 10 || cmdid > 51) + return 0; + + for (cmdp = pcmds; cmdp->function != NULL; cmdp++) + if (cmdp->id == cmdid) + break; + if (cmdp->function == NULL) + return 0; /* unsupported */ + return (*cmdp->function)(s->link, argc, argv); +} + +/* + * PC command handlers + */ + + /* Talk */ +int pc_10(struct link_t *l, int argc, char **argv) +{ + struct talk_t t; + struct nuser_t *nu; + + if (argc != 8) + return invalid_argc(l, 8, argc, argv); + + strncpy(t.fromcall, argv[1], sizeof(call_t)); + strncpy(t.tocall, argv[2], sizeof(call_t)); + strncpy(t.message, argv[3], sizeof(t.message)); + strncpy(t.fromnodec, argv[6], sizeof(call_t)); + t.via = l; + t.time = now; + + if ((nu = get_nuser(&t.tocall))) + t.tonode = nu->node; + else { + t.tonode = get_node(&t.tocall); + if (*argv[5] != ' ') + strncpy(t.tocall, argv[5], sizeof(call_t)); + } + + if (!t.tonode) + t.tonode = localnode; /* huh. */ + + net_talk(&t); + return 0; +} + + /* DX */ +int pc_11(struct link_t *l, int argc, char **argv) +{ + struct dx_t *d; + + if (argc != 9) + return invalid_argc(l, 9, argc, argv); + + d = hmalloc(sizeof(struct dx_t)); + + d->freq = str2freq(argv[1]); + strncpy(d->call, argv[2], sizeof(d->call)); + d->time = pcstr2t(argv[3], argv[4]); + strncpy(d->info, argv[5], sizeof(d->info)); + strncpy(d->fromcall, argv[6], sizeof(call_t)); + strncpy(d->fromnodec, argv[7], sizeof(call_t)); + d->hops = pchops2int(argv[8]); + d->via = l; + + net_dx(d); + return 0; +} + + /* Announcement */ +int pc_12(struct link_t *l, int argc, char **argv) +{ + struct ann_t *a; + + if (argc != 9) + return invalid_argc(l, 9, argc, argv); + + a = hmalloc(sizeof(struct ann_t)); + + strncpy(a->fromcall, argv[1], sizeof(call_t)); + strncpy(a->tonodec, argv[2], sizeof(call_t)); + strncpy(a->message, argv[3], sizeof(a->message)); + a->sysop = (*argv[4] == '*'); + strncpy(a->fromnodec, argv[5], sizeof(call_t)); + a->wx = (*argv[6] == '1'); + a->hops = pchops2int(argv[7]); + a->time = now; + a->via = l; + + net_announce(a); + return 0; +} + + /* Add user */ +int pc_16(struct link_t *l, int argc, char **argv) +{ + struct node_t *n; + struct nuser_t *nu, *nul, **prevp; + char *cm, *hr; + int i; + int hops; + + prevp = &nul; + if (!(n = get_node((call_t *)argv[1]))) + return 0; + hops = pchops2int(argv[argc-1]); + + for (i = 2; i < argc-1; i++) { + if (!(cm = strchr(argv[i], ' '))) + continue; + *cm = '\0'; + cm++; + if (!(hr = strchr(cm, ' '))) + continue; + *hr = '\0'; + hr++; + nu = hmalloc(sizeof(struct nuser_t)); + *prevp = nu; + nu->prevp = prevp; + prevp = &nu->next; + nu->next = NULL; + strncpy(nu->call, argv[i], sizeof(nu->call)); + nu->here = (*hr == '1'); + nu->since = now; + nu->name[0] = '\0'; + nu->node = n; + nu->hops = hops; + nu->away_str = NULL; + nu->away_time = now; + nu->sysop = 0; + nu->priviledged = 0; + } + + net_useradd(nul); + + return 0; +} + + /* Delete user */ +int pc_17(struct link_t *l, int argc, char **argv) +{ + struct nuser_t *nu; + struct node_t *n; + + if (argc != 4) + return invalid_argc(l, 4, argc, argv); + + if ( ((n = get_node((call_t *)argv[2]))) + && ((nu = get_nuserh((call_t *)argv[1], n))) ) + net_userdel(nu); + + return 0; +} + + /* Request link init */ +int pc_18(struct link_t *l, int argc, char **argv) +{ + if (argc != 4) + return invalid_argc(l, 4, argc, argv); + log(L_LINK, "PC: %s: requests link initialisation, sending tables", + l->name); + l->version = atoi(argv[2]); + + pc_sendnodes(l, nodes); + pc_sendusers(l, nusers); + pc_send(l, "PC20^\n"); + + return 0; +} + + /* Add node */ +int pc_19(struct link_t *l, int argc, char **argv) +{ + struct node_t *n, *nl, **prevp; + int i = 1; + int hops; + + prevp = &nl; + hops = pchops2int(argv[argc-1]); + + while (i < argc-2) { + if (i > argc - 5) + break; + n = hmalloc(sizeof(struct node_t)); + *prevp = n; + n->prevp = prevp; + prevp = &n->next; + n->next = NULL; + strncpy(n->call, argv[i+1], sizeof(n->call)); + n->here = (*argv[i] == '1'); + n->version = atoi(argv[i+3]); + n->via = l; + n->since = now; + n->hops = hops; + n->hops_ok = 0; + n->users_ok = 1; + n->users_known = 0; + n->users = 0; + n->rtt = 0; + n->rtt_ok = 0; + n->pinging = 0; + n->locked = 0; + i += 4; + } + + net_nodeadd(nl); + + return 0; +} + + /* Init done */ +int pc_20(struct link_t *l, int argc, char **argv) +{ + log(L_LINK, "PC: %s: Finished receiving tables, sending mine - link complete", + l->name); + + pc_sendnodes(l, nodes); + pc_sendusers(l, nusers); + pc_send(l, "PC22^\n"); + + link_finished(l); + + return 0; +} + + /* Delete node */ +int pc_21(struct link_t *l, int argc, char **argv) +{ + struct node_t *n; + + if (argc != 4) + return invalid_argc(l, 4, argc, argv); + + if ((n = get_node((call_t *)argv[1]))) + net_nodedel(n, argv[2]); + + return 0; +} + + /* PCDone */ +int pc_22(struct link_t *l, int argc, char **argv) +{ + log(L_LINK, "PC: %s: Finished receiving tables - link complete", + l->name); + + link_finished(l); + + return 0; +} + + /* WWV */ +int pc_23(struct link_t *l, int argc, char **argv) +{ + struct wwv_t *w; + struct tm *tm; + + if (argc != 11) + return invalid_argc(l, 11, argc, argv); + + w = hmalloc(sizeof(struct wwv_t)); + + w->time = pcstr2t(argv[1], argv[2]); + tm = gmtime(&w->time); + w->hour = tm->tm_hour; + w->sfi = atoi(argv[3]); + w->a = atoi(argv[4]); + w->k = atoi(argv[5]); + strncpy(w->forecast, argv[6], sizeof(w->forecast)); + strncpy(w->fromcall, argv[7], sizeof(call_t)); + strncpy(w->fromnodec, argv[8], sizeof(call_t)); + w->via = l; + w->hops = pchops2int(argv[9]); + + net_wwv(w); + + return 0; +} + + /* Loop check */ +int pc_38(struct link_t *l, int argc, char **argv) +{ + char *p, *p2; + + if (argc != 3) + return invalid_argc(l, 3, argc, argv); + + p2 = p = argv[1]; + while (p) { + p2 = strchr(p, ','); + if (p2) { + *p2 = '\0'; + p2++; + } + + if (get_node((call_t *)p)) { + /* LOOP */ + } + + p = p2; + } + + return 0; +} + + /* User & hop count beacon */ +int pc_50(struct link_t *l, int argc, char **argv) +{ + return 0; +} + + /* Ping */ +int pc_51(struct link_t *l, int argc, char **argv) +{ + if (argc != 4) + return invalid_argc(l, 4, argc, argv); + net_ping(l, (call_t *)argv[1], (call_t *)argv[2], atoi(argv[3])); return 0; } diff -urN clussed-19981224/net_pc.h clussed-19981227/net_pc.h --- clussed-19981224/net_pc.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_pc.h Sat Dec 26 19:03:01 1998 @@ -4,28 +4,36 @@ #include "network.h" +#define PCMAXLEN 240 #define pc_version 5480 +struct pcmd { + int id; + int (*function) (struct link_t *l, int argc, char **argv); +}; + extern int pc_msgstats[51]; -/* Leave these undefined for now - we really, really don't want them - to be called outside net_pc.c. - - extern char *hops2pcstr(int hops); - extern void pc_sendall(struct link_t *via, char *fmt, ...); -*/ +extern void pc_beacon(struct link_t *l); +extern void pc_ping(struct link_t *l, call_t *to, call_t *from, int flag); +extern void pc_reqclose(struct link_t *l, char *reason); +extern void pc_nodeadd(struct node_t *n); extern void pc_nodedel(struct node_t *n, char *reason); -extern void pc_sendloopcheck(struct link_t *l); -extern void pc_sendcluid(struct link_t *l); -extern void pc_handshake(struct link_t *l); + +extern void pc_useradd(struct nuser_t *nu); +extern void pc_userdel(struct nuser_t *nu); +extern void pc_useraway(struct nuser_t *nu); +extern void pc_userhere(struct nuser_t *nu); + extern void pc_dx(struct dx_t *dx); extern void pc_announce(struct ann_t *ann); extern void pc_wwv(struct wwv_t *wwv); extern void pc_talk(struct talk_t *t); -extern void pc_userdel(struct nuser_t *nu); -extern void pc_useraway(struct nuser_t *nu); -extern void pc_userhere(struct nuser_t *nu); + +extern void pc_sendloopcheck(struct link_t *l); +extern void pc_sendcluid(struct link_t *l); +extern void pc_conn_handler(struct link_t *l); extern void pc_disc_handler(struct csock_t *s); extern int pc_handler(struct csock_t *s, void *data, int len); diff -urN clussed-19981224/net_ping.c clussed-19981227/net_ping.c --- clussed-19981224/net_ping.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_ping.c Sat Dec 26 19:23:41 1998 @@ -11,17 +11,20 @@ #include "net_ping.h" #include "csock.h" #include "network.h" +#include "net_link.h" #include "luser.h" #include "cstring.h" #include "ctime.h" #include "log.h" +#include "timer.h" +#include "config.h" int ping_jobs; /* Amount of pinger jobs */ struct ping_t *pings; /* Pinger list */ -/* ====================================================================== */ -/* P I N G E R */ -/* ====================================================================== */ +/* + * Add a ping in the list, and send the ping forward + */ void ping_add(struct node_t *node, call_t *fromcall, int rtt_max) { @@ -46,10 +49,49 @@ p->node = node; p->next = NULL; - csprintf(node->via->sock, "PC51^%s^%s^1^\n", node->call, node->via->mycall); + link_ping(node->via, &node->call, fromcall, 1); } -/* ====================================================================== */ +/* + * Ping message received + */ + +void net_ping(struct link_t *l, call_t *tocall, call_t *fromcall, int flag) +{ + struct node_t *n; + + n = get_node(tocall); + + if (flag) { + if (n == localnode) { + log(L_PING, "Pinger: %s pings local node", + fromcall); + link_ping(l, fromcall, clucall, 0); + } else if (!strcmp((char *)tocall, l->mycall)) { + log(L_PING, "Pinger: %s pings local call %s", + fromcall, l->mycall); + link_ping(l, fromcall, &l->mycall, 0); + } else { + if (n) + ping_add(n, fromcall, PING_TIMEOUT); + } + } else { + if (n == localnode) { + log(L_PING, "Pinger: Received ping from %s", + fromcall); + } else if (!strcmp((char *)tocall, l->mycall)) { + log(L_PING, "Pinger: Received a ping from %s to local call %s", + fromcall, l->mycall); + } else { + if (n) + link_ping(n->via, tocall, fromcall, 0); + } + } +} + +/* + * Delete a ping from the list + */ int ping_del(struct node_t *node) { @@ -71,8 +113,10 @@ return 0; } -/* ====================================================================== */ - +/* + * Abort a ping + */ + void ping_abort(struct node_t *node, char *reason) { struct ping_t *p = pings; @@ -90,8 +134,9 @@ ping_del(node); } -/* ====================================================================== */ -/* This is called every second */ +/* + * This is called every second + */ void pinger_second(void) { @@ -99,7 +144,7 @@ while ((p = next)) { next = p->next; - if (time(NULL) - p->time >= p->rtt_max) { + if (now - p->time >= p->rtt_max) { log(L_PING, "Pinger: %s timed out", p->node->call); if (p->node == p->node->via->node) { /* Naapuri? */ @@ -111,8 +156,10 @@ } } -/* ====================================================================== */ - +/* + * Ping the command + */ + int cmd_ping(struct csock_t *s, int argc, char **argv) { struct node_t *n; @@ -146,8 +193,10 @@ return 0; } -/* ====================================================================== */ - +/* + * Pinger status command + */ + int cmd_pstatus(struct csock_t *s, int argc, char **argv) { struct ping_t *p = pings; @@ -162,7 +211,7 @@ csprintf(s, "%s%s%s\n", padleft((char *)&p->node->call, 10), padleft((char *)&p->fromcall, 10), - secs2str(time(NULL) - p->time)); + secs2str_l(now - p->time)); p = p->next; } return 0; diff -urN clussed-19981224/net_ping.h clussed-19981227/net_ping.h --- clussed-19981224/net_ping.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_ping.h Sat Dec 26 19:07:29 1998 @@ -18,6 +18,7 @@ }; extern void ping_add(struct node_t *node, call_t *fromcall, int rtt_max); +extern void net_ping(struct link_t *l, call_t *tocall, call_t *fromcall, int flag); extern int ping_del(struct node_t *node); /* Drop a ping */ extern void ping_abort(struct node_t *node, char *reason); /* Abort a ping */ diff -urN clussed-19981224/net_rdb.c clussed-19981227/net_rdb.c --- clussed-19981224/net_rdb.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_rdb.c Fri Dec 25 22:03:55 1998 @@ -1,7 +1,7 @@ #include "net_rdb.h" -void rdb_delnode(struct node_t *n) +void rdb_nodedel(struct node_t *n) { } diff -urN clussed-19981224/net_rdb.h clussed-19981227/net_rdb.h --- clussed-19981224/net_rdb.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_rdb.h Fri Dec 25 22:04:05 1998 @@ -4,6 +4,6 @@ #include "network.h" -void rdb_delnode(struct node_t *n); +void rdb_nodedel(struct node_t *n); #endif diff -urN clussed-19981224/net_user.c clussed-19981227/net_user.c --- clussed-19981224/net_user.c Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_user.c Fri Dec 25 22:14:48 1998 @@ -15,6 +15,7 @@ #include "log.h" #include "cluster.h" #include "f_nuser.h" +#include "timer.h" struct nuser_t *nusers; /* Users */ @@ -179,13 +180,13 @@ return; nu->here = 1; - nu->away_time = time(NULL); + nu->away_time = now; if (nu->away_str) { hfree(nu->away_str); nu->away_str = NULL; away_strings--; } - log(L_NUSER, "%s came back.", call); + log(L_NUSER, "User: %s came back", call); user_userhere(nu); link_userhere(nu); } @@ -208,85 +209,81 @@ else away_strings++; u->away_str = hstrdup(reason); - log(L_NUSER, "%s is away: %s", call, reason); + log(L_NUSER, "User: %s went away: %s", call, reason); } else - log(L_NUSER, "%s is away.", call); + log(L_NUSER, "User: %s went away.", call); link_useraway(u); u->here = 0; - u->away_time = time(NULL); + u->away_time = now; user_useraway(u); } /* - * Add an user + * Add a list of users */ -void net_adduser(struct nuser_t *nu) +void net_useradd(struct nuser_t *nu) { - int b; - struct nuser_t *p, *n; - char s[256]; - - p = nu; - sprintf(s, "PC16^%s", nu->node->call); - b = 0; + struct nuser_t *ul, *p, *next; + ul = p = nu; + p->prevp = &ul; + + /* Go through the users, remove invalid/duplicate ones, inform local users and files */ while (p) { - n = p->next; + next = p->next; - if (get_nuserh(&p->call, p->node) || (valid_call(&p->call) == -1)) + if (get_nuserh(&p->call, p->node) || (valid_call(&p->call) == -1)) { + if (p->next) + p->next->prevp = p->prevp; + *p->prevp = p->next; hfree(p); - else { - b++; - p->node->users++; - p->node->users_known = 1; - insert_nuser(p); + } else { if (p->node != localnode) - log(L_NUSER, "%s@%s login", p->call, p->node->call); + log(L_NUSER, "User: %s@%s logged in", p->call, p->node->call); user_useradd(p); - /* Spread the word */ - sprintf(s + strlen(s), "^%s - ", p->call); - if (p->here) - strcat(s, "1"); - else - strcat(s, "0"); set_homenode(p, &p->call, &p->node->call, 5); } - p = n; + p = next; } - if (b == 0) - return; - - sprintf(s + strlen(s), "^%s^\n", hops2pcstr(pc_hops)); - if (pc_hops <= 98) - pc_sendall(nu->node->via, (void *) s); /* !BUG! u might be freed! */ + link_useradd(ul); /* feed links */ + + /* Insert in user list */ + p = ul; + while (p) { + next = p->next; + p->node->users++; + p->node->users_known = 1; + insert_nuser(p); + p = next; + } } /* - * User login + * Local User login */ -struct nuser_t *nuser_login(struct link_t *l, call_t *call, struct node_t *n, - int here) +struct nuser_t *lnuser_login(struct luser_t *lu) { struct nuser_t *u; u = hmalloc(sizeof(struct nuser_t)); - strcpy(u->call, (char *)call); - u->node = n; + strcpy(u->call, (char *)lu->f->call); + u->node = localnode; *u->name = '\0'; - u->here = here; + u->here = 1; + u->hops = 0; u->away_str = NULL; - u->away_time = time(NULL); + u->away_time = now; u->sysop = 0; u->priviledged = 0; u->next = NULL; u->prevp = NULL; - u->time = time(NULL); - net_adduser(u); + u->since = now; + net_useradd(u); return u; } @@ -295,34 +292,17 @@ * Remove a cluster user */ -void net_deluser(struct link_t *l, struct nuser_t *nu) +void net_userdel(struct nuser_t *nu) { - nu->time = time(NULL); + nu->since = now; user_userdel(nu); - if (l) - log(L_NUSER, "%s@%s logout", nu->call, nu->node->call); + if (nu->node != localnode) + log(L_NUSER, "User: %s@%s logged out", nu->call, nu->node->call); link_userdel(nu); nu->node->users--; free_nuser(nu); -} - -/* - * User logout by callsign/node - */ - -void nuser_logout(struct link_t *l, call_t *call, struct node_t *n, time_t time) -{ - struct nuser_t *u; - - if ((l) && (n == localnode)) /* Check for a loop */ - return; - - if (!(u = get_nuserh(call, n))) - return; - - net_deluser(l, u); } diff -urN clussed-19981224/net_user.h clussed-19981227/net_user.h --- clussed-19981224/net_user.h Sun Dec 20 18:08:27 1998 +++ clussed-19981227/net_user.h Fri Dec 25 22:01:35 1998 @@ -17,12 +17,9 @@ /* User list handling */ void free_nusersn(struct node_t *n); -extern void net_adduser(struct nuser_t *nu); -extern void net_deluser(struct link_t *l, struct nuser_t *nu); -extern struct nuser_t *nuser_login(struct link_t *froml, call_t *call, - struct node_t *node, int here); -extern void nuser_logout(struct link_t *l, call_t *call, - struct node_t *n, time_t time); +extern void net_useradd(struct nuser_t *nu); +extern void net_userdel(struct nuser_t *nu); +extern struct nuser_t *lnuser_login(struct luser_t *lu); extern int count_users(void); /* Update user counts */ diff -urN clussed-19981224/network.c clussed-19981227/network.c --- clussed-19981224/network.c Thu Dec 24 16:09:07 1998 +++ clussed-19981227/network.c Sun Dec 27 03:11:27 1998 @@ -35,7 +35,6 @@ #include "cluster.h" #include "ui.h" -int pc_hops; int listened; int node_count; /* How many nodes */ @@ -88,7 +87,7 @@ free_nusersn(n); if (n->pinging) ping_abort(n, "Node vanished"); - rdb_delnode(n); + rdb_nodedel(n); *n->prevp = n->next; if (n->next) n->next->prevp = n->prevp; @@ -210,20 +209,16 @@ void drop_routes(struct link_t *l) { struct node_t *h, *n; - char s[256], s2[256]; + char s[256]; - sprintf(s, "%d nodes vanished due to link failure", l->routes); - sprintf(s2, "%s %sZ.", s, timestr_s(time(NULL))); - send_us(M_NODE, F_TIMESTAMP, (char*)&s2); - sprintf(s2, "%s.", s); - send_us(M_NODE, 0, (char *)&s2); + send_us(M_NODE, "%d nodes vanished due to link failure$t.", l->routes); h = nodes; while (h) { n = h->next; if (h->via == l) { - pc_hops = 0; sprintf(s, "%s <> %s link failed", (char *)&clucall, (char *)&l->call); + h->hops = 0; link_nodedel(h, s); free_node(h); } @@ -254,19 +249,23 @@ l->sock = sock; if (l->state == ls_held) { /* Held */ + l->dreason = dr_held; sock_disconnect(sock); return; } l->state = ls_init; - pc_sendloopcheck(l); - pc_sendcluid(l); + + l->sock->eolmode = eol_text; + l->sock->in_handler = pc_handler; + l->sock->disc_handler = pc_disc_handler; + + pc_conn_handler(l); + return; } - l->dreason = dr_held; + /* Whoa, duplikaatti! Katkaistaan molemmat... */ sock_disconnect(sock); sock_disconnect(l->sock); - - /* Whoa, duplikaatti! Katkaistaan molemmat... */ } /* @@ -331,12 +330,12 @@ void link_finished(struct link_t *l) { - log(L_LINK, "Linked to %s.", l->call); write_last("Linker", "%s %s - Linked to %s", - datestr_s_pad(time(NULL)), timestr_s(time(NULL)), l->call); + datestr_s_pad(now), timestr_s(now), l->call); + link_count++; l->state = ls_linked; l->dreason = dr_unknown; - l->since = time(NULL); + l->since = now; l->tries = 0; l->pc_beacon_timer = 0; l->ping_timer = 0; @@ -360,8 +359,7 @@ if (method == cl_rude || l->state == ls_init || l->mode == lm_listen) sock_disconnect(l->sock); else { - csprintf(l->sock, "PC39^%s^%s^\n", l->mycall, reason); - csflush(l->sock); + link_reqclose(l, reason); } if (l->tries == 0) l->tries++; @@ -387,15 +385,16 @@ log(L_LINK, "Link to %s failed (%s).", l->call, dr_str(l->dreason)); write_last("Linker", "%s %s - Link to %s failed.", - datestr_s_pad(time(NULL)), timestr_s(time(NULL)), l->call); + datestr_s_pad(now), timestr_s(now), l->call); user_linkdel(l, "unknown"); + link_count--; } l->state = ls_disc; } drop_routes(l); l->failures++; - l->since = time(NULL); + l->since = now; l->sock = 0; if (l->tries == 0) { l->retry_timer = l->retry_time - 1; @@ -403,7 +402,7 @@ } l->retry_timer = 0; if (l->backup) { - l->state = ls_backuped; + l->state = ls_backup; l->backup->state = ls_disc; } } @@ -421,7 +420,7 @@ void talk_back(int from, struct talk_t *t, struct talk_t *nt) { /* Send a message to the sender */ - nt->time = time(NULL); + nt->time = now; switch (from) { case 0: strcpy(nt->fromcall, (char *)clucall); @@ -433,7 +432,7 @@ strcpy(nt->fromnodec, (char *)clucall); strcpy(nt->tocall, t->fromcall); nt->tonode = get_node(&t->fromnodec); - nt->fromlink = NULL; + nt->via = NULL; net_talk(nt); } @@ -461,7 +460,7 @@ case 't': /* time */ sprintf(nt.message, "%s, uptime %s", - timestr(time(NULL)), secs2str(uptime())); + timestr(now), secs2str_l(uptime())); break; case 'q': @@ -567,7 +566,7 @@ return; u = get_nuser(&t->tocall); - if ((u) && (u->node->via != t->fromlink)) { /* Never route back, might loop */ + if ((u) && (u->node->via != t->via)) { /* Never route back, might loop */ /* Forward the message to another cluster node (should check for loops!) */ t->tonode = u->node; link_talk(t); @@ -695,55 +694,57 @@ } -/* ====================================================================== */ -/* Add a cluster node */ +/* + * Add a list of nodes + */ -void net_addnode(struct node_t *n) +void net_nodeadd(struct node_t *n) { - int i = 0; - struct node_t *p = n; - struct node_t *next; - struct link_t *via = n->via; - char s[256]; + struct node_t *nl, *p, *next; - strcpy(s, "PC19^"); - p = n; + nl = p = n; + p->prevp = &nl; while (p) { next = p->next; - if (get_node(&p->call) == NULL) { - i++; - - p->via->routes++; - if (!strcmp(p->call, p->via->call)) { - p->via->node = p; /* Its our neighbour! */ - } - insert_node(p); - - if (node_count > node_max) /* high water mark */ - node_max = node_count; - - log(L_NODE, "Node %s added", p->call); + if (get_node(&p->call)) { + if (p->next) + p->next->prevp = p->prevp; + *p->prevp = p->next; + hfree(p); + } else { + log(L_NODE, "Node: %s added", p->call); user_nodeadd(p); - strcat(s, (p->here) ? "1" : "0"); - sprintf(s + strlen(s), "^%s^0^%d^", p->call, p->version); - } else - free(p); + } p = next; } - if (!i) - return; + link_nodeadd(nl); /* feed links */ - if (pc_hops <= 98) { - sprintf(s + strlen(s), "%s^\n", hops2pcstr(pc_hops)); - pc_sendall(via, s); + /* insert in node list */ + p = nl; + while (p) { + next = p->next; + + p->via->routes++; + + if (!strcmp(p->call, p->via->call)) { + p->via->node = p; /* Its our neighbour! */ + p->via->version = p->version; + } + + insert_node(p); + + if (node_count > node_max) /* high water mark */ + node_max = node_count; + + p = next; } } -void net_delnode(struct node_t *n, char *reason) +void net_nodedel(struct node_t *n, char *reason) { - log(L_NODE, "Node %s vanished", n->call); + log(L_NODE, "Node: %s vanished", n->call); user_nodedel(n, reason); /* Notify local users */ link_nodedel(n, reason); /* Tell others */ free_node(n); /* Remove from the list */ @@ -771,12 +772,7 @@ l->pc_beacon_timer++; if (l->pc_beacon_timer == l->pc_beacon_interval) { l->pc_beacon_timer = 0; - csprintf(l->sock, "PC50^%s^%d^H", clucall, luser_count); - if (l->mode == lm_incoming) - csputs(l->sock, "1^\n"); - else - csputs(l->sock, "99^\n"); - csflush(l->sock); + link_beacon(l); } } @@ -784,11 +780,9 @@ if (l->state == ls_linked && l->ping_interval != 0) { l->ping_timer++; if (l->ping_timer == l->ping_interval) { - if (l->mode == lm_listen) { /* Just "ping" */ - csprintf(l->sock, "PC51^%s^%s^1^\n", - l->call, l->mycall); - csflush(l->sock); - } else + if (l->mode == lm_listen) /* Just "ping" */ + link_ping(l, &l->call, &l->mycall, 1); + else ping_add(l->node, &l->mycall, l->ping_maxrtt); l->ping_timer = 0; @@ -816,7 +810,7 @@ strcpy(localnode->call, (char *)clucall); localnode->via = NULL; - localnode->since = time(NULL); + localnode->since = now; localnode->version = pc_version; localnode->hops = 0; localnode->hops_ok = 1; @@ -831,6 +825,6 @@ localnode->prevp = &nodes; localnode->next = NULL; - set_timer(time(NULL) + 5, 60, (void (*)(void *ptr))&init_links, NULL); + set_timer(now + 5, 60, (void (*)(void *ptr))&init_links, NULL); } diff -urN clussed-19981224/network.h clussed-19981227/network.h --- clussed-19981224/network.h Thu Dec 24 16:08:44 1998 +++ clussed-19981227/network.h Sat Dec 26 15:17:05 1998 @@ -43,7 +43,7 @@ ls_disc, ls_init, ls_linked, - ls_backuped, + ls_backup, ls_held }; @@ -67,14 +67,14 @@ call_t call; /* Destination callsign */ call_t mycall; /* Local callsign used */ call_t link_call; /* Local AX.25 callsign used */ - + enum linkproto_t proto; /* Protocol used */ enum linkmode_t mode; /* Link mode */ enum linkstate_t state; /* Link state */ time_t since; /* When the state last changed */ enum dreason_t dreason; /* Why disconnected */ - int ver; /* Version number */ - + int version; /* Version number */ + struct csock_t *sock; /* Socket */ struct node_t *node; /* Neighbour node record */ @@ -115,15 +115,16 @@ }; struct nuser_t { - time_t time; /* Logged on since */ + time_t since; /* Logged on since */ call_t call; /* Callsign */ name_t name; /* Name */ struct node_t *node; /* Node */ + int hops; /* How many hops away */ int here; /* The here bit */ char *away_str; /* Away string */ time_t away_time; /* Away since */ int sysop; /* Onko sysop */ - int priviledged; /* Muuten vaan hyv„ j„tk„ */ + int priviledged; /* Muuten vaan hyvä jätkä */ /* Semi-doubly linked list: */ struct nuser_t **prevp; struct nuser_t *next; @@ -135,9 +136,10 @@ dxcall_t call; /* DX callsign */ unsigned long freq; /* Frequency, 1 decimal */ call_t fromcall; /* Who submitted the spot */ - call_t fromnodec; /* and on what node */ - struct link_t *fromlink; /* What link port did it come from */ + call_t fromnodec; /* at which node */ + struct link_t *via; /* What link port did it come from */ char info[81]; /* Misc text */ + int hops; /* How many hops */ }; struct ann_t { /* announce.clu */ @@ -146,10 +148,11 @@ call_t fromcall; /* From callsign */ call_t fromnodec; /* From node */ call_t tonodec; /* Distributed to node (* = full) */ - struct link_t *fromlink; /* What link port did it come from */ + struct link_t *via; /* What link port did it come from */ int sysop; /* Only to sysops */ int wx; /* Is it a WX spot */ char message[256]; /* The message itself */ + int hops; }; struct talk_t { @@ -159,7 +162,7 @@ call_t fromnodec; /* From node */ call_t tocall; /* Recipient's callsign */ struct node_t *tonode; /* Recipient's node */ - struct link_t *fromlink; /* What link port did it come from */ + struct link_t *via; /* What link port did it come from */ char message[256]; /* The message */ }; @@ -171,7 +174,8 @@ char forecast[81]; call_t fromcall; /* Who submitted this one */ call_t fromnodec; /* ...on what node... */ - struct link_t *fromlink; /* What link port did it come from */ + struct link_t *via; /* What link port did it come from */ + int hops; }; struct index_t { @@ -183,7 +187,6 @@ cl_nice, cl_rude }; -int pc_hops; int listened; /* Statistiikat: */ @@ -222,8 +225,8 @@ extern void net_wwv(struct wwv_t *wwv); /* WWV */ /* Node list handling */ -extern void net_addnode(struct node_t *n); /* Add cluster node */ -extern void net_delnode(struct node_t *n, char *reason); /* Del cluster node */ +extern void net_nodeadd(struct node_t *n); /* Add cluster node */ +extern void net_nodedel(struct node_t *n, char *reason); /* Del cluster node */ extern void net_minute(void); /* Called every minute */ extern void net_init(void); /* Initialize */