From 702fed3374753e6e5e7b8cec7c91d6d8c12e4632 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Mon, 2 Oct 2023 15:33:09 +0100 Subject: [PATCH] Create shfs project --- README.md | 7 +++++++ go.mod | 15 +++++++++++++++ go.sum | 21 +++++++++++++++++++++ main.go | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..ca9a967 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# shfs + +Sync Hash File System - allows syncing between devices and storing large files as references keyed by the file hash. + +Mount on linux: + +`mount -o port=,mountport=,nfsvers=3,noacl,tcp -t nfs localhost:/mount ` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..89684fd --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module github.com/1f349/shfs + +go 1.21.1 + +require ( + github.com/go-git/go-billy/v5 v5.5.0 + github.com/willscott/go-nfs v0.0.0-20230907145631-41b369691e46 +) + +require ( + github.com/google/uuid v1.3.1 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect + github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 // indirect + github.com/willscott/go-nfs-client v0.0.0-20200605172546-271fa9065b33 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..52c436b --- /dev/null +++ b/go.sum @@ -0,0 +1,21 @@ +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4= +github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 h1:UVArwN/wkKjMVhh2EQGC0tEc1+FqiLlvYXY5mQ2f8Wg= +github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93/go.mod h1:Nfe4efndBz4TibWycNE+lqyJZiMX4ycx+QKV8Ta0f/o= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/willscott/go-nfs v0.0.0-20230907145631-41b369691e46 h1:9dp+1bZsWG82VUuGeMPIT5JWzWpenWF9eSe2/N/dbCA= +github.com/willscott/go-nfs v0.0.0-20230907145631-41b369691e46/go.mod h1:1PiZswSlNu7GfHMWekF6rF1I94c8E0p+Cwbz7px1D14= +github.com/willscott/go-nfs-client v0.0.0-20200605172546-271fa9065b33 h1:Wd8wdpRzPXskyHvZLyw7Wc1fp5oCE2mhBCj7bAiibUs= +github.com/willscott/go-nfs-client v0.0.0-20200605172546-271fa9065b33/go.mod h1:cOUKSNty+RabZqKhm5yTJT5Vq/Fe83ZRWAJ5Kj8nRes= +github.com/zema1/go-nfs-client v0.0.0-20200604081958-0cf942f0e0fe/go.mod h1:im3CVJ32XM3+E+2RhY0sa5IVJVQehUrX0oE1wX4xOwU= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/main.go b/main.go new file mode 100644 index 0000000..a5928ef --- /dev/null +++ b/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "log" + "net" + + "github.com/go-git/go-billy/v5/memfs" + nfs "github.com/willscott/go-nfs" + nfshelper "github.com/willscott/go-nfs/helpers" +) + +func main() { + listener, err := net.Listen("tcp", ":0") + panicOnErr(err, "starting TCP listener") + fmt.Printf("Server running at %s\n", listener.Addr()) + mem := memfs.New() + f, err := mem.Create("hello.txt") + panicOnErr(err, "creating file") + _, err = f.Write([]byte("hello world")) + panicOnErr(err, "writing data") + f.Close() + handler := nfshelper.NewNullAuthHandler(mem) + cacheHelper := nfshelper.NewCachingHandler(handler, 1) + panicOnErr(nfs.Serve(listener, cacheHelper), "serving nfs") +} + +func panicOnErr(err error, desc ...interface{}) { + if err == nil { + return + } + log.Println(desc...) + log.Panicln(err) +}