1 #include "opensrf/transport_client.h"
2 #include "opensrf/transport_message.h"
4 #include "osrfConfig.h"
5 #include "opensrf/utils.h"
9 Maintains a set of transport clients for redundancy
12 //enum osrfTGType { OSRF_SERVER_NODE, OSRF_CLIENT_NODE };
14 struct __osrfTransportGroupStruct {
15 osrfList* list; /* our lisit of nodes */
16 char* router; /* the login username of the router on this network */
17 int currentNode; /* which node are we currently on. Used for client failover and
18 only gets updated on client messages where a server failed
19 and we need to move to the next server in the list */
21 typedef struct __osrfTransportGroupStruct osrfTransportGroup;
24 struct __osrfTransportGroupNode {
25 transport_client* connection; /* our connection to the network */
26 char* domain; /* the domain we're connected to */
27 char* username; /* username used to connect to the group of servers */
28 char* password; /* password used to connect to the group of servers */
29 char* resource; /* the login resource */
30 int port; /* port used to connect to the group of servers */
32 int active; /* true if we're able to send data on this connection */
33 time_t lastsent; /* the last time we sent a message */
35 typedef struct __osrfTransportGroupNode osrfTransportGroupNode;
39 Creates a new group node
40 @param domain The domain we're connecting to
41 @param port The port to connect on
42 @param username The login name
43 @param password The login password
44 @param resource The login resource
45 @return A new transport group node
47 osrfTransportGroupNode* osrfNewTransportGroupNode(
48 char* domain, int port, char* username, char* password, char* resource );
52 Allocates and initializes a new transport group.
53 The first node in the array is the default node for client connections.
54 @param router The router name shared accross the networks
55 @param nodes The nodes in the group.
57 osrfTransportGroup* osrfNewTransportGroup( char* router, osrfTransportGroupNode* nodes[], int count );
60 Attempts to connect all of the nodes in this group.
61 @param grp The transport group
62 @return The number of nodes successfully connected
64 int osrfTransportGroupConnect( osrfTransportGroup* grp );
68 Sends a transport message
69 If the message is destined for a domain that this group does not have a connection
70 for, then the message is sent out through the currently selected domain.
71 @param grp The transport group
72 @param type Whether this is a client request or a server response
73 @param msg The message to send
74 @param newdomain A pre-allocated buffer in which to write the name of the
75 new domain if a the expected domain could not be sent to.
76 @return 0 on normal successful send. Returns 1 if the message was sent
77 to a new domain (note: this can only happen when type == OSRF_CLIENT_NODE)
78 Returns -1 if the message cannot be sent.
80 int osrfTransportGroupSend( osrfTransportGroup* grp, transport_message* msg, char* newdomain );
82 int _osrfTGServerSend( osrfTransportGroup* grp, char* domain, transport_message* msg );
83 int _osrfTGClientSend( osrfTransportGroup* grp, char* domain, transport_message* msg );
86 Waits on all connections for inbound data.
87 @param grp The transport group
88 @param timeout How long to wait for data. 0 means check for data
89 but don't wait, a negative number means to wait indefinitely
90 @return The received message or NULL if the timeout occurred before a
93 transport_message* osrfTransportGroupRecvAll( osrfTransportGroup* grp, int timeout );
96 Waits for data from a single domain
97 @param grp The transport group
98 @param domain The domain to wait for data on
99 @param timeout see osrfTransportGroupRecvAll
101 transport_message* osrfTransportGroupRecv( osrfTransportGroup* grp, char* domain, int timeout );
104 Tells the group that the connect to the last message sent to the provided
105 domain did not make it through;
106 @param grp The transport group
107 @param comain The failed domain
109 void osrfTransportGroupSetInactive( osrfTransportGroup* grp, char* domain );
113 Finds a node in our list of nodes
115 osrfTransportGroupNode* __osrfTransportGroupFindNode( osrfTransportGroup* grp, char* domain );