1
0

oventi.h 7.0 KB

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