1
0

venti.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. VtEntryNoArchive = (1<<6), /* used for local storage: should not be set for Venti blocks */
  71. };
  72. struct VtRoot {
  73. ushort version;
  74. char name[128];
  75. char type[128];
  76. uchar score[VtScoreSize]; /* to a Dir block */
  77. ushort blockSize; /* maximum block size */
  78. uchar prev[VtScoreSize]; /* last root block */
  79. };
  80. struct VtEntry {
  81. ulong gen; /* generation number */
  82. ushort psize; /* pointer block size */
  83. ushort dsize; /* data block size */
  84. uchar depth; /* unpacked from flags */
  85. uchar flags;
  86. uvlong size;
  87. uchar score[VtScoreSize];
  88. };
  89. struct VtServerVtbl {
  90. Packet *(*read)(VtSession*, uchar score[VtScoreSize], int type, int n);
  91. int (*write)(VtSession*, uchar score[VtScoreSize], int type, Packet *p);
  92. void (*closing)(VtSession*, int clean);
  93. void (*sync)(VtSession*);
  94. };
  95. /* versions */
  96. enum {
  97. /* experimental versions */
  98. VtVersion01 = 1,
  99. VtVersion02,
  100. };
  101. /* score of zero length block */
  102. extern uchar vtZeroScore[VtScoreSize];
  103. /* both sides */
  104. void vtAttach(void);
  105. void vtDetach(void);
  106. void vtClose(VtSession *s);
  107. void vtFree(VtSession *s);
  108. char *vtGetUid(VtSession *s);
  109. char *vtGetSid(VtSession *s);
  110. int vtSetDebug(VtSession *s, int);
  111. int vtGetDebug(VtSession *s);
  112. int vtSetFd(VtSession *s, int fd);
  113. int vtGetFd(VtSession *s);
  114. int vtConnect(VtSession *s, char *password);
  115. int vtSetCryptoStrength(VtSession *s, int);
  116. int vtGetCryptoStrength(VtSession *s);
  117. int vtSetCompression(VtSession *s, int);
  118. int vtGetCompression(VtSession *s);
  119. int vtGetCrypto(VtSession *s);
  120. int vtGetCodec(VtSession *s);
  121. char *vtGetVersion(VtSession *s);
  122. char *vtGetError(void);
  123. int vtErrFmt(Fmt *fmt);
  124. void vtDebug(VtSession*, char *, ...);
  125. void vtDebugMesg(VtSession *z, Packet *p, char *s);
  126. /* internal */
  127. VtSession *vtAlloc(void);
  128. void vtReset(VtSession*);
  129. int vtAddString(Packet*, char*);
  130. int vtGetString(Packet*, char**);
  131. int vtSendPacket(VtSession*, Packet*);
  132. Packet *vtRecvPacket(VtSession*);
  133. void vtDisconnect(VtSession*, int);
  134. int vtHello(VtSession*);
  135. /* client side */
  136. VtSession *vtClientAlloc(void);
  137. VtSession *vtDial(char *server, int canfail);
  138. int vtRedial(VtSession*, char *server);
  139. VtSession *vtStdioServer(char *server);
  140. int vtPing(VtSession *s);
  141. int vtSetUid(VtSession*, char *uid);
  142. int vtRead(VtSession*, uchar score[VtScoreSize], int type, uchar *buf, int n);
  143. int vtWrite(VtSession*, uchar score[VtScoreSize], int type, uchar *buf, int n);
  144. Packet *vtReadPacket(VtSession*, uchar score[VtScoreSize], int type, int n);
  145. int vtWritePacket(VtSession*, uchar score[VtScoreSize], int type, Packet *p);
  146. int vtSync(VtSession *s);
  147. int vtZeroExtend(int type, uchar *buf, int n, int nn);
  148. int vtZeroTruncate(int type, uchar *buf, int n);
  149. int vtParseScore(char*, uint, uchar[VtScoreSize]);
  150. void vtRootPack(VtRoot*, uchar*);
  151. int vtRootUnpack(VtRoot*, uchar*);
  152. void vtEntryPack(VtEntry*, uchar*, int index);
  153. int vtEntryUnpack(VtEntry*, uchar*, int index);
  154. /* server side */
  155. VtSession *vtServerAlloc(VtServerVtbl*);
  156. int vtSetSid(VtSession *s, char *sid);
  157. int vtExport(VtSession *s);
  158. /* sha1 */
  159. VtSha1* vtSha1Alloc(void);
  160. void vtSha1Free(VtSha1*);
  161. void vtSha1Init(VtSha1*);
  162. void vtSha1Update(VtSha1*, uchar *, int n);
  163. void vtSha1Final(VtSha1*, uchar sha1[VtScoreSize]);
  164. void vtSha1(uchar score[VtScoreSize], uchar *, int);
  165. int vtSha1Check(uchar score[VtScoreSize], uchar *, int);
  166. int vtScoreFmt(Fmt *fmt);
  167. /* Packet */
  168. Packet *packetAlloc(void);
  169. void packetFree(Packet*);
  170. Packet *packetForeign(uchar *buf, int n, void (*free)(void *a), void *a);
  171. Packet *packetDup(Packet*, int offset, int n);
  172. Packet *packetSplit(Packet*, int n);
  173. int packetConsume(Packet*, uchar *buf, int n);
  174. int packetTrim(Packet*, int offset, int n);
  175. uchar *packetHeader(Packet*, int n);
  176. uchar *packetTrailer(Packet*, int n);
  177. int packetPrefix(Packet*, uchar *buf, int n);
  178. int packetAppend(Packet*, uchar *buf, int n);
  179. int packetConcat(Packet*, Packet*);
  180. uchar *packetPeek(Packet*, uchar *buf, int offset, int n);
  181. int packetCopy(Packet*, uchar *buf, int offset, int n);
  182. int packetFragments(Packet*, IOchunk*, int nio, int offset);
  183. int packetSize(Packet*);
  184. int packetAllocatedSize(Packet*);
  185. void packetSha1(Packet*, uchar sha1[VtScoreSize]);
  186. int packetCompact(Packet*);
  187. int packetCmp(Packet*, Packet*);
  188. void packetStats(void);
  189. /* portability stuff - should be a seperate library */
  190. void vtMemFree(void *);
  191. void *vtMemAlloc(int);
  192. void *vtMemAllocZ(int);
  193. void *vtMemRealloc(void *p, int);
  194. void *vtMemBrk(int n);
  195. char *vtStrDup(char *);
  196. void vtFatal(char *, ...);
  197. char *vtGetError(void);
  198. char *vtSetError(char *, ...);
  199. char *vtOSError(void);
  200. /* locking/threads */
  201. int vtThread(void (*f)(void*), void *rock);
  202. void vtThreadSetName(char*);
  203. VtLock *vtLockAlloc(void);
  204. /* void vtLockInit(VtLock**); */
  205. void vtLock(VtLock*);
  206. int vtCanLock(VtLock*);
  207. void vtRLock(VtLock*);
  208. int vtCanRLock(VtLock*);
  209. void vtUnlock(VtLock*);
  210. void vtRUnlock(VtLock*);
  211. void vtLockFree(VtLock*);
  212. VtRendez *vtRendezAlloc(VtLock*);
  213. void vtRendezFree(VtRendez*);
  214. int vtSleep(VtRendez*);
  215. int vtWakeup(VtRendez*);
  216. int vtWakeupAll(VtRendez*);
  217. /* fd functions - really network (socket) functions */
  218. void vtFdClose(int);
  219. int vtFdRead(int, uchar*, int);
  220. int vtFdReadFully(int, uchar*, int);
  221. int vtFdWrite(int, uchar*, int);
  222. /*
  223. * formatting
  224. * other than noted, these formats all ignore
  225. * the width and precision arguments, and all flags
  226. *
  227. * V a venti score
  228. * R venti error
  229. */
  230. #pragma varargck type "V" uchar*
  231. #pragma varargck type "R" void
  232. #pragma varargck argpos vtSetError 1