*** empty log message ***
[arla.git] / rx / rx-new.h
bloba12f3bb25cb51b216c90090bff21619177e38219
1 /*
2 * rx.h,v 1.7 1995/04/11 06:07:07 assar Exp
3 */
5 #ifndef _RX_
6 #define _RX_
8 #include <sys/types.h>
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <list.h>
12 #include <pthread.h>
13 #include <thrpool.h>
15 #include <rx_pkt.h>
17 /* XXX - This should be moved somewhere else and replaced with XDR */
19 typedef u_long unsigned32;
20 typedef u_short unsigned16;
22 /* Security garbage */
24 typedef struct rx_securityClass {
25 } rx_securityClass;
27 typedef struct rx_connection rx_connection;
29 typedef struct rx_call rx_call;
31 typedef struct rx_service rx_service;
33 #define RX_MAXDATA 1444 /* XXX - ??? */
36 typedef struct rx_wirepacket {
37 rx_header header;
38 char data[RX_MAXDATA];
39 } rx_wirepacket;
42 * There are two different types of acks.
43 * soft ack means that the packet has been receieved at the other end,
44 * but the sender should not throw away the packet yet. The receiver
45 * can still drop the packet or not give it to the application.
46 * The point of the soft acks is mainly flow-control.
48 * A hard ack means that the packet has been acknowledged by the
49 * application. Then the packet can be thrown away.
53 typedef enum {
54 RX_PKT_SOFT_ACK = 1
55 } rx_packet_flags;
57 typedef struct rx_packet {
58 rx_wirepacket wire;
59 unsigned datalen;
60 rx_call *call;
61 rx_packet_flags flags;
62 } rx_packet;
65 /* every call - i.e. RPC transaction */
67 struct rx_call {
68 enum { SENDING, RECEIVING } mode;
69 u_long callno; /* Call # of this connection */
70 u_long seqno; /* Seq # for packets */
71 int channelid; /* What channel are we using? */
72 rx_connection *conn;
73 List *recvpackets; /* List of received packets */
74 #if 0
75 List *ooopackets; /* Packets rec'd out-of-order */
76 #endif
77 rx_packet *thispacket; /* This packet, sending or receiving */
78 char *ptr; /* Here we should write data */
79 unsigned nleft; /* How much data there is left */
80 pthread_mutex_t mutex; /* Synchronisation */
81 pthread_cond_t cond;
84 /* This represents the on-going communication, i.e. a connection */
86 typedef enum {
87 RX_CONN_SERVER, /* This is a server */
88 RX_CONN_CLIENT /* The other side is a server */
89 } rx_connection_type;
91 #define RX_WINDOW 15
93 struct rx_connection {
94 time_t epoch; /* Time when this connection started */
95 u_long connid; /* Connection ID. How? */
96 struct sockaddr_in peer; /* The one we're talking to */
97 u_long serialno; /* Next serial number to use */
98 u_long callno[MAXCALLS]; /* Next call number to use */
99 rx_call *calls[MAXCALLS]; /* The on-going calls */
100 u_char secindex; /* Security index */
101 u_short serviceid; /* Service ID */
102 rx_connection_type type; /* Type of connection C-S or S-C */
103 u_long maxnoacked; /* Max packet sent and soft-acked */
104 List *packets; /* Not yet acked sent packets */
105 u_long window; /* Size of the window */
106 pthread_cond_t condsend; /* Conditional variable for sending */
107 pthread_mutex_t mutexsend; /* Mutex for above */
108 pthread_cond_t condrecv;
109 pthread_mutex_t mutexrecv;
110 rx_service *service; /* Service if server, else NULL */
114 * About packets:
116 * Here we keep the packets that have been sent but not yet
117 * hard-acked. When a packet has been soft-acked we set a flag in the
118 * packet_flags and stop the resend-timer.
121 struct rx_service {
122 u_short port;
123 u_short serviceid;
124 char *servicename;
125 int (*serviceproc)(rx_call *);
126 Thrpool *thrpool;
129 /* functions */
131 int rx_Init (int port);
133 rx_connection *rx_NewConnection (struct in_addr host, u_short port,
134 u_short service,
135 rx_securityClass *sec,
136 int secindex);
138 void rx_DestroyConnection (rx_connection *);
140 rx_call *rx_NewCall (rx_connection *);
142 int rx_EndCall (rx_call *, int);
144 rx_service *rx_NewService(u_short port, u_short serviceid,
145 char *servicename, rx_securityClass **so,
146 int nso, int (*serviceproc)(rx_call *));
148 int rx_Write (rx_call *, void *, int);
149 int rx_Read (rx_call *, void *, int);
150 int rx_FlushWrite (rx_call *call);
153 #endif /* _RX_ */
158 /* Old garbage */
160 #if 0
162 /* header of a RPC packet */
163 /* We should use XDR on this too. */
165 typedef enum {
166 HT_DATA = 1,
167 HT_ACK = 2,
168 HT_BUSY = 3,
169 HT_ABORT = 4,
170 HT_ACKALL = 5,
171 HT_CHAL = 6,
172 HT_RESP = 7,
173 HT_DEBUG = 8
174 } rx_header_type;
176 /* For flags in header */
178 enum {
179 HF_CLIENT_INITIATED = 1,
180 HF_REQ_ACK = 2,
181 HF_LAST = 4,
182 HF_MORE = 8};
184 #define MAXCALLS 4
186 #define CALL_MASK (MAXCALLS-1)
187 #define CONNID_MASK (~(MAXCALLS-1))
189 typedef struct rx_header {
190 unsigned32 epoch;
191 unsigned32 connid; /* And channel ID */
192 unsigned32 callid;
193 unsigned32 seqno; /* Call-based number */
194 unsigned32 serialno; /* Unique number */
195 u_char type;
196 u_char flags;
197 u_char status;
198 u_char secindex;
199 unsigned16 reserved; /* ??? verifier? */
200 unsigned16 serviceid;
201 /* This should be the other way around according to everything but */
202 /* tcpdump */
203 } rx_header;
205 #endif
207 #if 0
209 typedef enum {
210 RX_ACK_REQUESTED = 1,
211 RX_ACK_DUPLICATE = 2,
212 RX_ACK_OUT_OF_SEQUENCE = 3,
213 RX_ACK_EXEEDS_WINDOW = 4,
214 RX_ACK_NOSPACE = 5,
215 RX_ACK_PING = 6,
216 RX_ACK_PING_RESPONSE = 7,
217 RX_ACK_DELAY = 8
218 } rx_ack_reason;
220 typedef enum {
221 RX_ACK_TYPE_NACK = 0,
222 RX_ACK_TYPE_ACK = 1
223 } rx_ack_type;
225 #define RXMAXACKS 255
227 typedef struct rx_ack_packet {
228 unsigned16 bufferspace;
229 unsigned16 maxskew;
230 unsigned32 firstpacket; /* First packet in acks below */
231 unsigned32 prevpacket;
232 unsigned32 serial; /* Packet that prompted this one */
233 u_char reason; /* rx_ack_reason */
234 u_char nacks; /* # of acks */
235 u_char acks[RXMAXACKS]; /* acks (rx_ack_type) */
236 } rx_ack_packet;
238 #endif