venti.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. /* client side */
  126. VtSession *vtClientAlloc(void);
  127. VtSession *vtDial(char *server, int canfail);
  128. int vtRedial(VtSession*, char *server);
  129. VtSession *vtStdioServer(char *server);
  130. int vtPing(VtSession *s);
  131. int vtSetUid(VtSession*, char *uid);
  132. int vtRead(VtSession*, uchar score[VtScoreSize], int type, uchar *buf, int n);
  133. int vtWrite(VtSession*, uchar score[VtScoreSize], int type, uchar *buf, int n);
  134. Packet *vtReadPacket(VtSession*, uchar score[VtScoreSize], int type, int n);
  135. int vtWritePacket(VtSession*, uchar score[VtScoreSize], int type, Packet *p);
  136. int vtSync(VtSession *s);
  137. int vtZeroExtend(int type, uchar *buf, int n, int nn);
  138. int vtZeroTruncate(int type, uchar *buf, int n);
  139. void vtRootPack(VtRoot*, uchar*);
  140. int vtRootUnpack(VtRoot*, uchar*);
  141. void vtEntryPack(VtEntry*, uchar*, int index);
  142. int vtEntryUnpack(VtEntry*, uchar*, int index);
  143. /* server side */
  144. VtSession *vtServerAlloc(VtServerVtbl*);
  145. int vtSetSid(VtSession *s, char *sid);
  146. int vtExport(VtSession *s);
  147. /* sha1 */
  148. VtSha1* vtSha1Alloc(void);
  149. void vtSha1Free(VtSha1*);
  150. void vtSha1Init(VtSha1*);
  151. void vtSha1Update(VtSha1*, uchar *, int n);
  152. void vtSha1Final(VtSha1*, uchar sha1[VtScoreSize]);
  153. void vtSha1(uchar score[VtScoreSize], uchar *, int);
  154. int vtSha1Check(uchar score[VtScoreSize], uchar *, int);
  155. int vtScoreFmt(Fmt *fmt);
  156. /* Packet */
  157. Packet *packetAlloc(void);
  158. void packetFree(Packet*);
  159. Packet *packetForeign(uchar *buf, int n, void (*free)(void *a), void *a);
  160. Packet *packetDup(Packet*, int offset, int n);
  161. Packet *packetSplit(Packet*, int n);
  162. int packetConsume(Packet*, uchar *buf, int n);
  163. int packetTrim(Packet*, int offset, int n);
  164. uchar *packetHeader(Packet*, int n);
  165. uchar *packetTrailer(Packet*, int n);
  166. int packetPrefix(Packet*, uchar *buf, int n);
  167. int packetAppend(Packet*, uchar *buf, int n);
  168. int packetConcat(Packet*, Packet*);
  169. uchar *packetPeek(Packet*, uchar *buf, int offset, int n);
  170. int packetCopy(Packet*, uchar *buf, int offset, int n);
  171. int packetFragments(Packet*, IOchunk*, int nio, int offset);
  172. int packetSize(Packet*);
  173. int packetAllocatedSize(Packet*);
  174. void packetSha1(Packet*, uchar sha1[VtScoreSize]);
  175. int packetCompact(Packet*);
  176. int packetCmp(Packet*, Packet*);
  177. void packetStats(void);
  178. /* portability stuff - should be a seperate library */
  179. void vtMemFree(void *);
  180. void *vtMemAlloc(int);
  181. void *vtMemAllocZ(int);
  182. void *vtMemRealloc(void *p, int);
  183. void *vtMemBrk(int n);
  184. char *vtStrDup(char *);
  185. void vtFatal(char *, ...);
  186. char *vtGetError(void);
  187. char *vtSetError(char *, ...);
  188. char *vtOSError(void);
  189. /* locking/threads */
  190. int vtThread(void (*f)(void*), void *rock);
  191. void vtThreadSetName(char*);
  192. VtLock *vtLockAlloc(void);
  193. void vtLockInit(VtLock**);
  194. void vtLock(VtLock*);
  195. int vtCanLock(VtLock*);
  196. void vtRLock(VtLock*);
  197. int vtCanRLock(VtLock*);
  198. void vtUnlock(VtLock*);
  199. void vtRUnlock(VtLock*);
  200. void vtLockFree(VtLock*);
  201. VtRendez *vtRendezAlloc(VtLock*);
  202. void vtRendezFree(VtRendez*);
  203. int vtSleep(VtRendez*);
  204. int vtWakeup(VtRendez*);
  205. int vtWakeupAll(VtRendez*);
  206. /* fd functions - really network (socket) functions */
  207. void vtFdClose(int);
  208. int vtFdRead(int, uchar*, int);
  209. int vtFdReadFully(int, uchar*, int);
  210. int vtFdWrite(int, uchar*, int);
  211. /*
  212. * formatting
  213. * other than noted, these formats all ignore
  214. * the width and precision arguments, and all flags
  215. *
  216. * V a venti score
  217. * R venti error
  218. */
  219. #pragma varargck type "V" uchar*
  220. #pragma varargck type "R" void
  221. #pragma varargck argpos vtSetError 1