netproto_internal.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef NETPROTO_INTERNAL_H_
  2. #define NETPROTO_INTERNAL_H_
  3. #include <stdint.h>
  4. #include "crypto.h"
  5. #include "tsnetwork.h"
  6. struct netproto_connection_internal {
  7. int (* cancel)(void *);
  8. void * cookie;
  9. int fd;
  10. NETWORK_WRITEQ * Q;
  11. CRYPTO_SESSION * keys;
  12. struct sleepcookie {
  13. int handle;
  14. network_callback * callback;
  15. void * cookie;
  16. } sleepcookie;
  17. uint64_t bytesin;
  18. uint64_t bytesout;
  19. uint64_t bytesqueued;
  20. int broken;
  21. };
  22. /**
  23. * netproto_alloc(callback, cookie):
  24. * Allocate a network protocol connection cookie. If the connection is closed
  25. * before netproto_setfd is called, netproto_close will call callback(cookie)
  26. * in lieu of performing callback cancels on a socket.
  27. */
  28. struct netproto_connection_internal * netproto_alloc(int (*)(void *), void *);
  29. /**
  30. * netproto_setfd(C, fd):
  31. * Set the network protocol connection cookie ${C} to use connected socket
  32. * ${fd}. This function must be called exactly once after netproto_alloc
  33. * before calling any other functions aside from netproto_free.
  34. */
  35. int netproto_setfd(struct netproto_connection_internal *, int);
  36. /**
  37. * netproto_keyexchange(C, useragent, callback, cookie):
  38. * Perform protocol negotiation and key exchange with the tarsnap server
  39. * on the newly opened connection with cookie ${C}. When the negotiation
  40. * is complete or has failed, call callback(cookie, status) where status is
  41. * a NETPROTO_STATUS_* value.
  42. */
  43. int netproto_keyexchange(struct netproto_connection_internal *, const char *,
  44. network_callback *, void *);
  45. #endif /* !NETPROTO_INTERNAL_H_ */