Skip to content

Commit

Permalink
Remove more unused stuff in network code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolfering committed Oct 11, 2024
1 parent a06b22e commit 5e1b890
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 1,079 deletions.
80 changes: 0 additions & 80 deletions PBProjects/AlephOne.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

22 changes: 1 addition & 21 deletions Source_Files/Misc/sdl_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
// Note that the SDL network microphone code is the one sending "big" packets these days.
#define ddpMaxData 1500

typedef char NetEntityName[32];
typedef IPaddress NetAddrBlock;

/* ---------- DDPFrame and PacketBuffer (DDP) */
Expand All @@ -58,30 +57,14 @@ typedef struct DDPFrame DDPFrame, *DDPFramePtr;

struct DDPPacketBuffer
{
byte protocolType;
NetAddrBlock sourceAddress;

uint16 datagramSize;
byte datagramData[ddpMaxData];
};
typedef struct DDPPacketBuffer DDPPacketBuffer, *DDPPacketBufferPtr;

/* ---------- ConnectionEnd (ADSP) */

struct ConnectionEnd
{
TCPsocket socket;
TCPsocket server_socket;
SDLNet_SocketSet server_socket_set;
};
typedef struct ConnectionEnd ConnectionEnd, *ConnectionEndPtr;

/* ---------- types */

typedef NetEntityName *NetEntityNamePtr;

typedef void (*lookupUpdateProcPtr)(short message, short index);
typedef bool (*lookupFilterProcPtr)(NetEntityName *entity, NetAddrBlock *address);
typedef void (*PacketHandlerProcPtr)(DDPPacketBufferPtr packet);

/* ---------- prototypes/NETWORK.C */
Expand All @@ -99,9 +82,6 @@ std::string NetSessionIdentifier(void);

/* ---------- prototypes/NETWORK_DDP.C */

OSErr NetDDPOpen(void);
OSErr NetDDPClose(void);

// ZZZ: this is a bit confusing; in the original AppleTalk DDP code, the socket routines
// took and returned a socket number, which is a bit like the file descriptor one gets for
// a UNIX socket. Now with NETWORK_IP, that portion of the API is used to pass an IP port number.
Expand All @@ -113,7 +93,7 @@ OSErr NetDDPCloseSocket(short ignored);
DDPFramePtr NetDDPNewFrame(void);
void NetDDPDisposeFrame(DDPFramePtr frame);

OSErr NetDDPSendFrame(DDPFramePtr frame, const NetAddrBlock *address, short protocolType, short socket);
OSErr NetDDPSendFrame(DDPFramePtr frame, const NetAddrBlock *address);

/* ---------- prototypes/NETWORK_ADSP.C */

Expand Down
7 changes: 3 additions & 4 deletions Source_Files/Network/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ noinst_LIBRARIES = libnetwork.a
SUBDIRS = Metaserver StandaloneHub

libnetwork_a_SOURCES = ConnectPool.h network.h network_capabilities.h \
network_data_formats.h network_dialog_widgets_sdl.h network_dialogs.h \
network_distribution_types.h network_games.h network_lookup_sdl.h \
network_dialog_widgets_sdl.h network_dialogs.h network_games.h \
network_messages.h network_private.h network_star.h NetworkGameProtocol.h \
SDL_netx.h SSLP_API.h SSLP_Protocol.h StarGameProtocol.h \
Update.h HTTP.h PortForward.h Pinger.h \
\
ConnectPool.cpp network.cpp network_capabilities.cpp \
network_data_formats.cpp network_dialogs.cpp network_dialog_widgets_sdl.cpp \
network_games.cpp network_lookup_sdl.cpp network_messages.cpp \
network_dialogs.cpp network_dialog_widgets_sdl.cpp \
network_games.cpp network_messages.cpp \
network_star_hub.cpp network_star_spoke.cpp network_udp.cpp \
SDL_netx.cpp SSLP_limited.cpp StarGameProtocol.cpp \
Update.cpp HTTP.cpp PortForward.cpp Pinger.cpp
Expand Down
2 changes: 1 addition & 1 deletion Source_Files/Network/Pinger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void Pinger::Ping(uint8_t number_of_tries, bool unpinged_addresses_only)
{
for (int i = 0; i < number_of_tries; i++)
{
if (NetDDPSendFrame(ping_packet, &address.ipv4, kPROTOCOL_TYPE, 0) == 0 && !address.ping_sent_tick)
if (NetDDPSendFrame(ping_packet, &address.ipv4) == 0 && !address.ping_sent_tick)
{
address.ping_sent_tick = machine_tick_count();
}
Expand Down
17 changes: 0 additions & 17 deletions Source_Files/Network/SSLP_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,6 @@ SSLP_Allow_Service_Discovery(const SSLP_ServiceInstance* inServiceInstance);



// SSLP_Hint_Service_Discovery: start periodically announcing the presence of a service-instance to a named machine and port.
// (this is useful if you need a way to connect machines in different broadcast domains, which ordinarily would not see
// each other by SSLP.)
// If remoteHost->port is 0, the default SSLP_PORT will be used. This is almost certainly what you want.
// Make sure the data in inRemoteHost are in network (big-endian) byte order!
// If Allow_Service_Discovery was not already called for this service-instance, it's called by this function.
// The data you provide are copied, so you may do whatever you like with your own storage afterwards.
// NB!! in the current (limited) implementation, a call to this function with a service-instance that differs
// from the one provided to Allow_Service_Discovery is an ERROR and may lead to odd results.
// (calling this without having called Allow_Service_Discovery is ok, and makes the other call for you.)
// Calling this with a different serviceInstance or remote address will change the hinting behavior to reflect
// your wishes.
void
SSLP_Hint_Service_Discovery(const SSLP_ServiceInstance* inServiceInstance, const IPaddress* inRemoteHost);



// SSLP_Disallow_Service_Discovery: stop letting other machines know that the service-instance is available.
// If NULL is provided, the effect is of calling Disallow_Service_Discovery on every currently-discoverable service instance.
// Also stops hinting the applicable service-instance(s), if appropriate.
Expand Down
16 changes: 7 additions & 9 deletions Source_Files/Network/SSLP_Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#ifndef SSLP_PROTOCOL_H
#define SSLP_PROTOCOL_H

#include <SDL2/SDL_net.h>


#ifndef SSLP_PORT
#define SSLP_PORT 15367 // I made this up, change if it sucks
Expand Down Expand Up @@ -113,13 +111,13 @@
#endif

struct SSLP_Packet {
Uint32 sslpp_magic; // should always be SSLPP_MAGIC
Uint32 sslpp_version; // set to SSLPP_VERSION, for catching version mismatch
Uint32 sslpp_message; // set to SSLPP_MESSAGE_*
Uint16 sslpp_service_port; // only valid in HAVE messages, states on which port the service can be contacted.
Uint16 sslpp_reserved; // should always be 0
char sslpp_service_type[SSLP_MAX_TYPE_LENGTH]; // type desired, for FIND; type provided or no longer provided on HAVE or LOST
char sslpp_service_name[SSLP_MAX_NAME_LENGTH]; // name of the service instance. meaningless in FIND.
uint32_t sslpp_magic; // should always be SSLPP_MAGIC
uint32_t sslpp_version; // set to SSLPP_VERSION, for catching version mismatch
uint32_t sslpp_message; // set to SSLPP_MESSAGE_*
uint16_t sslpp_service_port; // only valid in HAVE messages, states on which port the service can be contacted.
uint16_t sslpp_reserved; // should always be 0
char sslpp_service_type[SSLP_MAX_TYPE_LENGTH]; // type desired, for FIND; type provided or no longer provided on HAVE or LOST
char sslpp_service_name[SSLP_MAX_NAME_LENGTH]; // name of the service instance. meaningless in FIND.
};

// The packed size and packed-packet type
Expand Down
86 changes: 4 additions & 82 deletions Source_Files/Network/SSLP_limited.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
#define SSLPINT_NONE 0x00
#define SSLPINT_LOCATING 0x01
#define SSLPINT_RESPONDING 0x02
#define SSLPINT_HINTING 0x04

// found service instances expire after not hearing from them for this many milliseconds
#define SSLPINT_INSTANCE_TIMEOUT 20000
Expand Down Expand Up @@ -603,7 +602,7 @@ SSLP_Allow_Service_Discovery(const struct SSLP_ServiceInstance* inServiceInstanc

assert(inServiceInstance != NULL);

assert(!(sBehaviorsDesired & (SSLPINT_RESPONDING | SSLPINT_HINTING)));
assert(!(sBehaviorsDesired & SSLPINT_RESPONDING));

if(sBehaviorsDesired == SSLPINT_NONE)
if(!SSLPint_Enter())
Expand Down Expand Up @@ -641,55 +640,6 @@ SSLP_Allow_Service_Discovery(const struct SSLP_ServiceInstance* inServiceInstanc
}


void
SSLP_Hint_Service_Discovery(const struct SSLP_ServiceInstance* inServiceInstance, const IPaddress* inAddress) {
logContext("starting to hint SSLP service discovery");

// If we're not already allowing discovery, start doing it
if(!(sBehaviorsDesired & SSLPINT_RESPONDING))
SSLP_Allow_Service_Discovery(inServiceInstance);


// If we are not already hinting, get a packet to work with.
if(!(sBehaviorsDesired & SSLPINT_HINTING))
sHintPacket = SDLNet_AllocPacket(SIZEOF_SSLP_Packet);


// We hint the service passed to the address passed - if we are already responding with a service instance
// (thanks to Allow_Service_Discovery called separately) they may be different services! This behavior should
// be considered odd (in the current one-service-instance implementation) and ought to be avoided.


assert(sHintPacket != NULL);

// set up the "HAVE" packet
sHintPacket->len = sizeof(struct SSLP_Packet);
sHintPacket->channel = -1; // channel is ignored
sHintPacket->address.host = inAddress->host;
sHintPacket->address.port = inAddress->port;
if(sHintPacket->address.port == 0)
sHintPacket->address.port = SDL_SwapBE16(SSLP_PORT);

SSLP_Packet UnpackedPacket;
SSLP_Packet *theHintPacket = &UnpackedPacket;

theHintPacket->sslpp_magic = SDL_SwapBE32(SSLPP_MAGIC);
theHintPacket->sslpp_version = SDL_SwapBE32(SSLPP_VERSION);
theHintPacket->sslpp_message = SDL_SwapBE32(SSLPP_MESSAGE_HAVE);
theHintPacket->sslpp_service_port = inServiceInstance->sslps_address.port;
theHintPacket->sslpp_reserved = 0; // unused - set to 0
// note: my strncpy states it fills remaining buffer with 0. If yours doesn't, fill it yourself.
strncpy(theHintPacket->sslpp_service_type, inServiceInstance->sslps_type, SSLP_MAX_TYPE_LENGTH);
strncpy(theHintPacket->sslpp_service_name, inServiceInstance->sslps_name, SSLP_MAX_NAME_LENGTH);

// Start up the hinting behavior, in case we weren't already.
sBehaviorsDesired |= SSLPINT_HINTING;

// Load into the "real" packet
PackPacket(sHintPacket->data,theHintPacket);
}


void
SSLP_Disallow_Service_Discovery(const struct SSLP_ServiceInstance* inInstance) {
// Officially, we would walk through a list to find the right one to disallow (or, if NULL is passed in,
Expand All @@ -700,28 +650,6 @@ SSLP_Disallow_Service_Discovery(const struct SSLP_ServiceInstance* inInstance) {

assert(sBehaviorsDesired & SSLPINT_RESPONDING);


// If we're hinting, cut it out
if(sBehaviorsDesired & SSLPINT_HINTING) {
// Unicast a LOST packet, as a courtesy

struct SSLP_Packet UnpackedHintPacket;
struct SSLP_Packet* theHintPacket = &UnpackedHintPacket;
UnpackPacket(sHintPacket->data,theHintPacket);

theHintPacket->sslpp_message = SDL_SwapBE32(SSLPP_MESSAGE_LOST);
PackPacket(sHintPacket->data,theHintPacket);
SDLNet_UDP_Send(sSocketDescriptor, -1, sHintPacket);

// Clean up the hinting packet
SDLNet_FreePacket(sHintPacket);
sHintPacket = NULL;

// No longer hinting
sBehaviorsDesired &= ~SSLPINT_HINTING;
}


// Indicate we no longer want to allow discovery
sBehaviorsDesired &= ~SSLPINT_RESPONDING;

Expand Down Expand Up @@ -760,20 +688,14 @@ SSLP_Pump() {

Uint32 theCurrentTime = machine_tick_count();

if(sBehaviorsDesired & (SSLPINT_LOCATING | SSLPINT_HINTING)) {
if(sBehaviorsDesired & SSLPINT_LOCATING) {

// Do some work only once every five seconds
if(theCurrentTime - theTimeLastWorked >= 5000) {

// Do broadcasting work
if(sBehaviorsDesired & SSLPINT_LOCATING) {
SDLNetx_UDP_Broadcast(sSocketDescriptor, sFindPacket);
SSLPint_RemoveTimedOutInstances();
}

// Do hinting work
if(sBehaviorsDesired & SSLPINT_HINTING)
SDLNet_UDP_Send(sSocketDescriptor, -1, sHintPacket);
SDLNetx_UDP_Broadcast(sSocketDescriptor, sFindPacket);
SSLPint_RemoveTimedOutInstances();

theTimeLastWorked = theCurrentTime;
}
Expand Down
1 change: 0 additions & 1 deletion Source_Files/Network/StandaloneHub/standalone_hub_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
http://www.gnu.org/licenses/gpl.html
*/

#include <SDL2/SDL_net.h>
#include "Logging.h"
#include "DefaultStringSets.h"
#include "preferences.h"
Expand Down
Loading

0 comments on commit 5e1b890

Please sign in to comment.