venti.h 6.8 KB

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