oventi.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #pragma lib "liboventi.a"
  10. #pragma src "/sys/src/liboventi"
  11. typedef struct VtSession VtSession;
  12. typedef struct VtSha1 VtSha1;
  13. typedef struct Packet Packet;
  14. typedef struct VtLock VtLock;
  15. typedef struct VtRendez VtRendez;
  16. typedef struct VtRoot VtRoot;
  17. typedef struct VtEntry VtEntry;
  18. typedef struct VtServerVtbl VtServerVtbl;
  19. #pragma incomplete VtSession
  20. #pragma incomplete VtSha1
  21. #pragma incomplete Packet
  22. #pragma incomplete VtLock
  23. #pragma incomplete VtRendez
  24. enum {
  25. VtScoreSize = 20, /* Venti */
  26. VtMaxLumpSize = 56*1024,
  27. VtPointerDepth = 7,
  28. VtEntrySize = 40,
  29. VtRootSize = 300,
  30. VtMaxStringSize = 1000,
  31. VtAuthSize = 1024, /* size of auth group - in bits - must be multiple of 8 */
  32. MaxFragSize = 9*1024,
  33. VtMaxFileSize = (1ULL<<48) - 1,
  34. VtRootVersion = 2,
  35. };
  36. /* crypto strengths */
  37. enum {
  38. VtCryptoStrengthNone,
  39. VtCryptoStrengthAuth,
  40. VtCryptoStrengthWeak,
  41. VtCryptoStrengthStrong,
  42. };
  43. /* crypto suites */
  44. enum {
  45. VtCryptoNone,
  46. VtCryptoSSL3,
  47. VtCryptoTLS1,
  48. VtCryptoMax
  49. };
  50. /* codecs */
  51. enum {
  52. VtCodecNone,
  53. VtCodecDeflate,
  54. VtCodecThwack,
  55. VtCodecMax
  56. };
  57. /* Lump Types */
  58. enum {
  59. VtErrType, /* illegal */
  60. VtRootType,
  61. VtDirType,
  62. VtPointerType0,
  63. VtPointerType1,
  64. VtPointerType2,
  65. VtPointerType3,
  66. VtPointerType4,
  67. VtPointerType5,
  68. VtPointerType6,
  69. VtPointerType7, /* not used */
  70. VtPointerType8, /* not used */
  71. VtPointerType9, /* not used */
  72. VtDataType,
  73. VtMaxType
  74. };
  75. /* Dir Entry flags */
  76. enum {
  77. VtEntryActive = (1<<0), /* entry is in use */
  78. VtEntryDir = (1<<1), /* a directory */
  79. VtEntryDepthShift = 2, /* shift for pointer depth */
  80. VtEntryDepthMask = (0x7<<2), /* mask for pointer depth */
  81. VtEntryLocal = (1<<5), /* used for local storage: should not be set for Venti blocks */
  82. VtEntryNoArchive = (1<<6), /* used for local storage: should not be set for Venti blocks */
  83. };
  84. struct VtRoot {
  85. uint16_t version;
  86. char name[128];
  87. char type[128];
  88. uint8_t score[VtScoreSize]; /* to a Dir block */
  89. uint16_t blockSize; /* maximum block size */
  90. uint8_t prev[VtScoreSize]; /* last root block */
  91. };
  92. struct VtEntry {
  93. uint32_t gen; /* generation number */
  94. uint16_t psize; /* pointer block size */
  95. uint16_t dsize; /* data block size */
  96. uint8_t depth; /* unpacked from flags */
  97. uint8_t flags;
  98. uint64_t size;
  99. uint8_t score[VtScoreSize];
  100. };
  101. struct VtServerVtbl {
  102. Packet *(*read)(VtSession*, uint8_t score[VtScoreSize], int type,
  103. int n);
  104. int (*write)(VtSession*, uint8_t score[VtScoreSize], int type,
  105. Packet *p);
  106. void (*closing)(VtSession*, int clean);
  107. void (*sync)(VtSession*);
  108. };
  109. /* versions */
  110. enum {
  111. /* experimental versions */
  112. VtVersion01 = 1,
  113. VtVersion02,
  114. };
  115. /* score of zero length block */
  116. extern uint8_t vtZeroScore[VtScoreSize];
  117. /* both sides */
  118. void vtAttach(void);
  119. void vtDetach(void);
  120. void vtClose(VtSession *s);
  121. void vtFree(VtSession *s);
  122. char *vtGetUid(VtSession *s);
  123. char *vtGetSid(VtSession *s);
  124. int vtSetDebug(VtSession *s, int);
  125. int vtGetDebug(VtSession *s);
  126. int vtSetFd(VtSession *s, int fd);
  127. int vtGetFd(VtSession *s);
  128. int vtConnect(VtSession *s, char *password);
  129. int vtSetCryptoStrength(VtSession *s, int);
  130. int vtGetCryptoStrength(VtSession *s);
  131. int vtSetCompression(VtSession *s, int);
  132. int vtGetCompression(VtSession *s);
  133. int vtGetCrypto(VtSession *s);
  134. int vtGetCodec(VtSession *s);
  135. char *vtGetVersion(VtSession *s);
  136. char *vtGetError(void);
  137. int vtErrFmt(Fmt *fmt);
  138. void vtDebug(VtSession*, char *, ...);
  139. void vtDebugMesg(VtSession *z, Packet *p, char *s);
  140. /* internal */
  141. VtSession *vtAlloc(void);
  142. void vtReset(VtSession*);
  143. int vtAddString(Packet*, char*);
  144. int vtGetString(Packet*, char**);
  145. int vtSendPacket(VtSession*, Packet*);
  146. Packet *vtRecvPacket(VtSession*);
  147. void vtDisconnect(VtSession*, int);
  148. int vtHello(VtSession*);
  149. /* client side */
  150. VtSession *vtClientAlloc(void);
  151. VtSession *vtDial(char *server, int canfail);
  152. int vtRedial(VtSession*, char *server);
  153. VtSession *vtStdioServer(char *server);
  154. int vtPing(VtSession *s);
  155. int vtSetUid(VtSession*, char *uid);
  156. int vtRead(VtSession*, uint8_t score[VtScoreSize], int type, uint8_t *buf,
  157. int n);
  158. int vtWrite(VtSession*, uint8_t score[VtScoreSize], int type, uint8_t *buf,
  159. int n);
  160. Packet *vtReadPacket(VtSession*, uint8_t score[VtScoreSize], int type,
  161. int n);
  162. int vtWritePacket(VtSession*, uint8_t score[VtScoreSize], int type,
  163. Packet *p);
  164. int vtSync(VtSession *s);
  165. int vtZeroExtend(int type, uint8_t *buf, int n, int nn);
  166. int vtZeroTruncate(int type, uint8_t *buf, int n);
  167. int vtParseScore(char*, uint, uint8_t[VtScoreSize]);
  168. void vtRootPack(VtRoot*, uint8_t*);
  169. int vtRootUnpack(VtRoot*, uint8_t*);
  170. void vtEntryPack(VtEntry*, uint8_t*, int index);
  171. int vtEntryUnpack(VtEntry*, uint8_t*, int index);
  172. /* server side */
  173. VtSession *vtServerAlloc(VtServerVtbl*);
  174. int vtSetSid(VtSession *s, char *sid);
  175. int vtExport(VtSession *s);
  176. /* sha1 */
  177. VtSha1* vtSha1Alloc(void);
  178. void vtSha1Free(VtSha1*);
  179. void vtSha1Init(VtSha1*);
  180. void vtSha1Update(VtSha1*, uint8_t *, int n);
  181. void vtSha1Final(VtSha1*, uint8_t sha1[VtScoreSize]);
  182. void vtSha1(uint8_t score[VtScoreSize], uint8_t *, int);
  183. int vtSha1Check(uint8_t score[VtScoreSize], uint8_t *, int);
  184. int vtScoreFmt(Fmt *fmt);
  185. /* Packet */
  186. Packet *packetAlloc(void);
  187. void packetFree(Packet*);
  188. Packet *packetForeign(uint8_t *buf, int n, void (*free)(void *a), void *a);
  189. Packet *packetDup(Packet*, int offset, int n);
  190. Packet *packetSplit(Packet*, int n);
  191. int packetConsume(Packet*, uint8_t *buf, int n);
  192. int packetTrim(Packet*, int offset, int n);
  193. uint8_t *packetHeader(Packet*, int n);
  194. uint8_t *packetTrailer(Packet*, int n);
  195. int packetPrefix(Packet*, uint8_t *buf, int n);
  196. int packetAppend(Packet*, uint8_t *buf, int n);
  197. int packetConcat(Packet*, Packet*);
  198. uint8_t *packetPeek(Packet*, uint8_t *buf, int offset, int n);
  199. int packetCopy(Packet*, uint8_t *buf, int offset, int n);
  200. int packetFragments(Packet*, IOchunk*, int nio, int offset);
  201. int packetSize(Packet*);
  202. int packetAllocatedSize(Packet*);
  203. void packetSha1(Packet*, uint8_t sha1[VtScoreSize]);
  204. int packetCompact(Packet*);
  205. int packetCmp(Packet*, Packet*);
  206. void packetStats(void);
  207. /* portability stuff - should be a seperate library */
  208. void vtMemFree(void *);
  209. void *vtMemAlloc(int);
  210. void *vtMemAllocZ(int);
  211. void *vtMemRealloc(void *p, int);
  212. void *vtMemBrk(int n);
  213. char *vtStrDup(char *);
  214. void vtFatal(char *, ...);
  215. char *vtGetError(void);
  216. char *vtSetError(char *, ...);
  217. char *vtOSError(void);
  218. /* locking/threads */
  219. int vtThread(void (*f)(void*), void *rock);
  220. void vtThreadSetName(char*);
  221. VtLock *vtLockAlloc(void);
  222. /* void vtLockInit(VtLock**); */
  223. void vtLock(VtLock*);
  224. int vtCanLock(VtLock*);
  225. void vtRLock(VtLock*);
  226. int vtCanRLock(VtLock*);
  227. void vtUnlock(VtLock*);
  228. void vtRUnlock(VtLock*);
  229. void vtLockFree(VtLock*);
  230. VtRendez *vtRendezAlloc(VtLock*);
  231. void vtRendezFree(VtRendez*);
  232. int vtSleep(VtRendez*);
  233. int vtWakeup(VtRendez*);
  234. int vtWakeupAll(VtRendez*);
  235. /* fd functions - really network (socket) functions */
  236. void vtFdClose(int);
  237. int vtFdRead(int, uint8_t*, int);
  238. int vtFdReadFully(int, uint8_t*, int);
  239. int vtFdWrite(int, uint8_t*, int);
  240. /*
  241. * formatting
  242. * other than noted, these formats all ignore
  243. * the width and precision arguments, and all flags
  244. *
  245. * V a venti score
  246. * R venti error
  247. */
  248. #pragma varargck type "V" uchar*
  249. #pragma varargck type "R" void
  250. #pragma varargck argpos vtSetError 1