group
group__libshare__net
The libshare Socket Handling provides access to regular socket operations with posix or convienence functions in addition to access to the ESP network protocol.

Network socket operations.

The ESP protocol performs streaming compression and provides more security than TCP. The libshare network socket operations.
typedef
typedef struct shnet_t shnet_t
variable
shnet_t _sk_table[65536]
[65536]
socket
function
int shnet_accept
(int sockfd)
accept
function
int shnet_bindsk
(int sockfd, char *hostname, unsigned int port)
bind
function
int shnet_bind
(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
bind
function
int shnet_listen
(int sockfd, int backlog)
listen
function
int shnet_close
(int sk)
close
function
int shnet_conn
(int sk, char *host, unsigned short port, int async)
connect
function
int shnet_fcntl
(int fd, int cmd, long arg)
fcntl
function
struct hostent* shresolve
(char *hostname)
gethost
function
struct sockaddr* shaddr
(int sockfd)
getaddr
function
const char* shaddr_print
(struct sockaddr *addr)
getaddr
function
ssize_t shnet_read
(int fd, const void *buf, size_t count)
Reads or buffers data content from a socket.
Param
fd
The file descriptor opened with or . shnet_sk() group__libshare__net_1ga0762a18a7420961416ddd0677a151fca member shnet_socket() group__libshare__net_1gae7937b44d1e895c738ba99e44c585494 member
buf
The buffer to write data into or NULL in order to buffer the information.
count
The maximum size of the data buffer.
Return Value
The number of bytes read, 0 when an asynchronous connection has no information to read, or a negative libshare error code.
Note
The error code SHERR_CONNRESET is returned when the remote peer naturally closes the socket connection.
function
int shnet_sk
(void)
Creates a standard IPv4 TCP socket.
function
int shnet_socket
(int domain, int type, int protocol)
Create a network socket.
Param
domain
Either AF_INET or AF_INET6.
type
Only SOCK_STREAM is supported.
protocol
Either IPPROTO_TCP or IPPROTO_SHNET.
function
struct sockaddr* shnet_host
(int sockfd)
socket
function
ssize_t shnet_write
(int fd, const void *buf, size_t count)
Write data content to a socket.
Param
fd
The file descriptor opened with or . shnet_sk() group__libshare__net_1ga0762a18a7420961416ddd0677a151fca member shnet_socket() group__libshare__net_1gae7937b44d1e895c738ba99e44c585494 member
buf
The data content to be written.
count
The size of the data content.
Return Value
The number of bytes written or a libshare error code.
function
int shnet_write_flush
(int fd)
function
int shnet_verify
(fd_set *readfds, fd_set *writefds, long *millis)
Waits on the specified read/write socket streams and marks which are available for an IO operation.
See
shnet_select() group__libshare__net_1ga064abd9c114957a942448ebdb6d07134 member
function
int shselect
(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Performs a POSIX select() against a set of socket streams. shnet_t structshnet__t compound
function
int shconnect
(int sk, struct sockaddr *skaddr, socklen_t skaddr_len)
Initiate a standard posix connection managable by libshare.
function
int shconnect_host
(char *host, unsigned short port, int flags)
* Initiate a connection to the hostname and port specified.
function
int shconnect_peer
(shpeer_t *peer, int flags)
* Initiate a socket connection to a libshare peer entity.
function
shbuf_t* shnet_read_buf
(int fd)
Obtain the internal socket buffer used for a network connection.
function
int shnet_write_buf
(int fd, unsigned char *data, size_t data_len)
function
int shnet_flags
(int fd)
function
shdb_t* shnet_track_open
(char *name)
Open the peer tracking database for the current application.
Param
A
specific database name or NULL for the default.
function
void shnet_track_close
(shdb_t *db)
Close a pre-opened peer tracking database.
function
int shnet_track_add
(shdb_t *db, shpeer_t *peer)
Adds a new peer entity to the track db.
function
int shnet_track_mark
(shdb_t *db, shpeer_t *peer, int cond)
function
int shnet_track_incr
(shdb_t *db, shpeer_t *peer)
function
int shnet_track_decr
(shdb_t *db, shpeer_t *peer)
function
int shnet_track_remove
(shdb_t *db, shpeer_t *peer)
function
int shnet_track_find
(shdb_t *db, shpeer_t *peer)
function
int shnet_track_count
(shdb_t *db, char *app_name)
function
shpeer_t** shnet_track_scan
(shdb_t *db, shpeer_t *peer, int list_max)
Provides a list of the oldest peer(s) marked for the service associated with the provided peer.
Param
db
The database to scan [from the network track table].
peer
The peer to search for a matching service.
Return Value
An allocated array of peers which needs to be freed via the "free()" call.
Note
A maximum of 1000 records is returned.
function
shpeer_t** shnet_track_list
(shdb_t *db, shpeer_t *peer, int list_max)
Provides a list of the most trusted peer(s).
Return Value
An allocated array of peers which needs to be freed via the "free()" call.
function
int shnet_track_verify
(shpeer_t *peer, int *sk_p)
Verify whether a network connect is accessible.
Param
sk_p
Must be set to zero on initial call.
function
int shnet_track_prune
(char *name)
Remove records that have more negative connections than positive.
Param
The
name of the "network tracking" database.
define
USHORT_MAX
65536
define
IPPROTO
ESTP 121
define
SHNET_ALIVE
(1 << 0)
socket is not closed
define
SHNET_CONNECT
(1 << 1)
perform asynchronous connection
define
SHNET_ASYNC
(1 << 2)
do not block client calls
define
SHNET_LISTEN
(1 << 3)
socket is bound to listen on port.
define
SHNET_SHUTDOWN
(1 << 5)
Automatically terminate socket after a successful connection.
define
SHNET_TRACK
(1 << 6)
Record connection fail/success in sharefs peer database.
define
SHNET_CRYPT
(1 << 7)
Socket communication is encrypted by the libshare API.
define
SHNET_HASH
(1 << 8)
Underlying protocol 'hashing' is performed by the libshare API.
define
SHNET_CERT
(1 << 9)
Access to socket communication is authorized by a certificate.
define
SHNET_DEFAULT_DEVICE
"eth0"
define
TX_NONE
0
A generic type referencing an invalid transaction.
define
TX_INIT
1
define
TX_SUBSCRIBE
2
A transaction mode to request broadcasts of a transaction type.
Note
Only applicable for client message-queue communication.
define
TX_IDENT
3
A specfic application's reference to an account.
define
TX_ACCOUNT
4
An identifier of user credentials.
define
TX_SESSION
5
An active application session for an identity.
define
TX_APP
6
A libshare application identifier.
define
TX_FILE
7
A share-fs partition file transaction.
define
TX_WARD
8
A ward can be placed on another transaction to prohibit from being used.
define
TX_TRUST
9
A secondary confirmation of a transaction.
define
TX_LEDGER
10
A collection of transactions.
define
TX_LICENSE
11
A license granting access permission.
define
TX_METRIC
12
An account metric of identification.
define
TX_MEM
13
A memory pool transaction.
define
TX_VM
14
A task performing sexe execution thread(s).
define
TX_RUN
15
A sexe runtime execution thread.
define
TX_WALLET
16
A wallet owned by an identity.
define
TX_BOND
17
A virtual currency transaction.
define
TX_ASSET
18
"Anything tangible or intangible that can be owned or controlled to produce value and that is held to have positive economic value."
define
TX_CONTRACT
19
An agreement, or offer, to exchange two denominations of two assets.
define
TX_EVENT
20
An event specifies the duration of another transaction.
See
shicald
define
TX_EVAL
21
A negative or positive value for an identify in reference to a contextual event.
define
TX_CONTEXT
22
define
TX_REFERENCE
23
define
TX_CLOCK
24
define
MAX_TX
25
The maximum number of transaction operations currently supported.
define
MAX_VERSION_TX
256
The maximum number of transaction operations ever supported.
define
TX_ASSET_NONE
0
define
TX_ASSET_PERSON
1
define
TX_ASSET_ORGANIZATION
2
define
TX_ASSET_SYSTEM
3
define
TX_ASSET_SOFTWARE
4
define
TX_ASSET_DATABASE
5
define
TX_ASSET_NETWORK
6
define
TX_ASSET_SERVICE
7
define
TX_ASSET_DATA
8
define
TX_ASSET_DEVICE
9
define
TX_ASSET_CIRCUIT
10
define
TX_ASSET_DAEMON
11
A network service provider such as a web hosting daemon.
define
TX_ASSET_BOND
12
define
MAX_TX_ASSETS
13
define
TX_BOND_NONE
0
define
TX_BOND_PREPARE
1
define
TX_BOND_SCHEDULE
2
define
TX_BOND_TRANSMIT
3
define
TX_BOND_CONFIRM
4
define
TX_BOND_PENDING
5
define
TX_BOND_COMPLETE
6
define
TX_BONDERR_ADDR
10
define
TX_BONDERR_ACCOUNT
11
define
TX_BONDERR_DEBIT
12
define
TX_BONDERR_NET
13
define
TX_BONDERR_SESS
14
define
NET_DB_NAME
"net"
define
TRACK_TABLE_NAME
"track"
define
shnet_select
(shselect((_fd), (_readfd), (_writefd), (_excfd), (_to)))
A convience function for calling shselect.