1
0

oventi.h 7.0 KB

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