From e83369d4cc31ea72d8c3bdc56eeb7ad080bf3e67 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 19 Aug 2022 09:04:22 -0700 Subject: [PATCH 1/4] Add checks for download folder existence prior to downloading --- go.mod | 16 +- go.sum | 303 +----------- utils/eventHandler.go | 1083 +++++++++++++++++++++-------------------- 3 files changed, 568 insertions(+), 834 deletions(-) diff --git a/go.mod b/go.mod index 86c4712..1d7bedf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go -go 1.15 +go 1.18 require ( cwtch.im/cwtch v0.17.1 @@ -8,8 +8,20 @@ require ( git.openprivacy.ca/openprivacy/connectivity v1.8.5 git.openprivacy.ca/openprivacy/log v1.0.3 github.com/mutecomm/go-sqlcipher/v4 v4.4.2 - golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect +) + +require ( + filippo.io/edwards25519 v1.0.0-rc.1 // indirect + git.openprivacy.ca/cwtch.im/tapir v0.5.4 // indirect + git.openprivacy.ca/openprivacy/bine v0.0.4 // indirect + github.com/gtank/merlin v0.1.1 // indirect + github.com/gtank/ristretto255 v0.1.2 // indirect + github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect + go.etcd.io/bbolt v1.3.4 // indirect + golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect + golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a // indirect golang.org/x/text v0.3.7 // indirect ) + diff --git a/go.sum b/go.sum index 1a0148f..6af1fe6 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,3 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -cwtch.im/cwtch v0.14.9/go.mod h1:/fLuoYLY/7JHw6RojFojpd245CiOcU24QpWqzh9FRDI= -cwtch.im/cwtch v0.17.1 h1:6+llVGiy3/um1X9v6zndCQoYMDVRiz8pC46CPy9ahaE= -cwtch.im/cwtch v0.17.1/go.mod h1:P1P559+8tW9hnFcGys4rmpOVm3E/DHd3C49Sb9P6KbE= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= git.openprivacy.ca/cwtch.im/server v1.4.2 h1:ZcRK1XuWvJzNjYdAvAISD8HcEITPwWbvRiIZGkMKu1k= @@ -32,60 +16,16 @@ git.openprivacy.ca/openprivacy/connectivity v1.8.5/go.mod h1:pG50Dq4IelxFGyF1y8d git.openprivacy.ca/openprivacy/log v1.0.2/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= git.openprivacy.ca/openprivacy/log v1.0.3 h1:E/PMm4LY+Q9s3aDpfySfEDq/vYQontlvNj/scrPaga0= git.openprivacy.ca/openprivacy/log v1.0.3/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cucumber/gherkin-go/v19 v19.0.3/go.mod h1:jY/NP6jUtRSArQQJ5h1FXOUgk5fZK24qtE7vKi776Vw= -github.com/cucumber/godog v0.12.0/go.mod h1:u6SD7IXC49dLpPN35kal0oYEjsXZWee4pW6Tm9t5pIc= -github.com/cucumber/messages-go/v16 v16.0.0/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= -github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -93,239 +33,72 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc= github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= -github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-memdb v1.3.0/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= -github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= -github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA= github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG9WsDpiCvZf1yKO7sz7scAjSlBa0= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= -github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= -github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mutecomm/go-sqlcipher/v4 v4.4.2 h1:eM10bFtI4UvibIsKr10/QT7Yfz+NADfjZYh0GKrXUNc= github.com/mutecomm/go-sqlcipher/v4 v4.4.2/go.mod h1:mF2UmIpBnzFeBdu/ypTDb/LdbS0nk0dfSN1WUsWTjMA= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.0.0-rc2 h1:2ukZwTHG/SAlJe4mm5xTdcUYH7IRvldIXhukE1pQBeY= github.com/onsi/ginkgo/v2 v2.0.0-rc2/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -337,64 +110,22 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a h1:ppl5mZgokTT8uPkmYOyEUmPTr3ypaKkg5eFOGrAmxxE= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -402,33 +133,15 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -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= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/utils/eventHandler.go b/utils/eventHandler.go index b65e718..40f410d 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -1,657 +1,666 @@ package utils import ( - "encoding/json" - "fmt" - "os" - "strconv" + "encoding/json" + "fmt" + "os" + "strconv" - "cwtch.im/cwtch/app" - "cwtch.im/cwtch/app/plugins" - "cwtch.im/cwtch/model" - "cwtch.im/cwtch/model/attr" - "cwtch.im/cwtch/model/constants" - "cwtch.im/cwtch/peer" - "cwtch.im/cwtch/protocol/connections" - constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" - "git.openprivacy.ca/openprivacy/log" + "cwtch.im/cwtch/app" + "cwtch.im/cwtch/app/plugins" + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/model/constants" + "cwtch.im/cwtch/peer" + "cwtch.im/cwtch/protocol/connections" + constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" + "git.openprivacy.ca/openprivacy/log" - "time" + "time" - "cwtch.im/cwtch/event" - "cwtch.im/cwtch/functionality/filesharing" + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/functionality/filesharing" ) type EventProfileEnvelope struct { - Event event.Event - Profile string + Event event.Event + Profile string } type EventHandler struct { - app app.Application - appBusQueue event.Queue - profileEvents chan EventProfileEnvelope + app app.Application + appBusQueue event.Queue + profileEvents chan EventProfileEnvelope } // We should be reading from profile events pretty quickly, but we make this buffer fairly large... const profileEventsBufferSize = 512 func NewEventHandler() *EventHandler { - eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} - return eh + eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} + return eh } func (eh *EventHandler) HandleApp(application app.Application) { - eh.app = application - application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) + eh.app = application + application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) } func (eh *EventHandler) GetNextEvent() string { - appChan := eh.appBusQueue.OutChan() + appChan := eh.appBusQueue.OutChan() - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - default: - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - case ev := <-eh.profileEvents: - return eh.handleProfileEvent(&ev) - } - } + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + default: + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + case ev := <-eh.profileEvents: + return eh.handleProfileEvent(&ev) + } + } } // handleAppBusEvent enriches AppBus events so they are usable with out further data fetches func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { - if eh.app != nil { - switch e.EventType { - case event.ACNStatus: - if e.Data[event.Progress] == "100" { - for _, onion := range eh.app.ListProfiles() { - // launch a listen thread (internally this does a check that the protocol engine is not listening) - // and as such is safe to call. - eh.app.GetPeer(onion).Listen() - } - } - case event.NewPeer: - onion := e.Data[event.Identity] - profile := eh.app.GetPeer(e.Data[event.Identity]) - if profile == nil { - log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") - break - } - log.Debug("New Peer Event: %v", e) + if eh.app != nil { + switch e.EventType { + case event.ACNStatus: + if e.Data[event.Progress] == "100" { + for _, onion := range eh.app.ListProfiles() { + // launch a listen thread (internally this does a check that the protocol engine is not listening) + // and as such is safe to call. + eh.app.GetPeer(onion).Listen() + } + } + case event.NewPeer: + onion := e.Data[event.Identity] + profile := eh.app.GetPeer(e.Data[event.Identity]) + if profile == nil { + log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") + break + } + log.Debug("New Peer Event: %v", e) - if e.Data["Reload"] != event.True { - eh.startHandlingPeer(onion) - } + if e.Data["Reload"] != event.True { + eh.startHandlingPeer(onion) + } - // CwtchPeer will always set this now... - tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) - e.Data[constants.Tag] = tag + // CwtchPeer will always set this now... + tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) + e.Data[constants.Tag] = tag - if e.Data[event.Created] == event.True { - profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) - } + if e.Data[event.Created] == event.True { + profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) + } - profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) - eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) - eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) + profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) + eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) + eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) - // If the user has chosen to block unknown profiles - // then explicitly configure the protocol engine to do so.. - settings := ReadGlobalSettings() - if settings.BlockUnknownConnections { - profile.BlockUnknownConnections() - } else { - // For completeness - profile.AllowUnknownConnections() - } + // If the user has chosen to block unknown profiles + // then explicitly configure the protocol engine to do so.. + settings := ReadGlobalSettings() + if settings.BlockUnknownConnections { + profile.BlockUnknownConnections() + } else { + // For completeness + profile.AllowUnknownConnections() + } - // Start up the Profile - profile.Listen() - profile.StartPeersConnections() - if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { - profile.StartServerConnections() - } + // Start up the Profile + profile.Listen() + profile.StartPeersConnections() + if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { + profile.StartServerConnections() + } - online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) - // Name always exists - e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) - // if a custom profile image exists then default to it. - key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - if !exists { - e.Data[constants2.Picture] = RandomProfileImage(onion) - } else { - e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) - serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) - profile.ShareFile(key, serializedManifest) - log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) - } + online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) + // Name always exists + e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) + // if a custom profile image exists then default to it. + key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + if !exists { + e.Data[constants2.Picture] = RandomProfileImage(onion) + } else { + e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) + serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) + profile.ShareFile(key, serializedManifest) + log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) + } - // Resolve the profile image of the profile. + // Resolve the profile image of the profile. - e.Data["Online"] = online + e.Data["Online"] = online - // If file sharing is enabled then reshare all active files... - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - if err == nil { - fsf.ReShareFiles(profile) - } + // If file sharing is enabled then reshare all active files... + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + if err == nil { + fsf.ReShareFiles(profile) + } - // Construct our conversations and our srever lists - var contacts []Contact - var servers []groups.Server + // Construct our conversations and our srever lists + var contacts []Contact + var servers []groups.Server - conversations, err := profile.FetchConversations() + conversations, err := profile.FetchConversations() - if err == nil { - // We have conversations attached to this profile... - for _, conversationInfo := range conversations { - // Only compile the server info if we have enabled the experiment... - // Note that this means that this info can become stale if when first loaded the experiment - // has been disabled and then is later re-enabled. As such we need to ensure that this list is - // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... - if conversationInfo.IsServer() { - groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) - if err == nil { - servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) - } - continue - } + if err == nil { + // We have conversations attached to this profile... + for _, conversationInfo := range conversations { + // Only compile the server info if we have enabled the experiment... + // Note that this means that this info can become stale if when first loaded the experiment + // has been disabled and then is later re-enabled. As such we need to ensure that this list is + // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... + if conversationInfo.IsServer() { + groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) + if err == nil { + servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) + } + continue + } - // Prefer local override to public name... - name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - name = conversationInfo.Handle - } - } + // Prefer local override to public name... + name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + name = conversationInfo.Handle + } + } - // Resolve the profile image of the contact - var cpicPath string - var defaultPath string - if conversationInfo.IsGroup() { - cpicPath = RandomGroupImage(conversationInfo.Handle) - defaultPath = RandomGroupImage(conversationInfo.Handle) - } else { - cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) - defaultPath = RandomProfileImage(conversationInfo.Handle) - } + // Resolve the profile image of the contact + var cpicPath string + var defaultPath string + if conversationInfo.IsGroup() { + cpicPath = RandomGroupImage(conversationInfo.Handle) + defaultPath = RandomGroupImage(conversationInfo.Handle) + } else { + cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) + defaultPath = RandomProfileImage(conversationInfo.Handle) + } - // Resolve Save History Setting - saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) - if !set { - saveHistory = event.DeleteHistoryDefault - } + // Resolve Save History Setting + saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) + if !set { + saveHistory = event.DeleteHistoryDefault + } - // Resolve Archived Setting - isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) - if !set { - isArchived = event.False - } + // Resolve Archived Setting + isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) + if !set { + isArchived = event.False + } - unread := 0 - lastSeenMessageId := -1 - lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) - if set { - lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) - if err == nil { - // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) - messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) - if err == nil { - for _, message := range messages { - msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) - if err == nil { - if msgTime.UTC().After(lastSeenTime.UTC()) { - unread++ - } else { - lastSeenMessageId = message.ID - break - } - } - } - } - } - } + unread := 0 + lastSeenMessageId := -1 + lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) + if set { + lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) + if err == nil { + // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) + messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) + if err == nil { + for _, message := range messages { + msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) + if err == nil { + if msgTime.UTC().After(lastSeenTime.UTC()) { + unread++ + } else { + lastSeenMessageId = message.ID + break + } + } + } + } + } + } - groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) + groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) - stateHandle := conversationInfo.Handle - if conversationInfo.IsGroup() { - stateHandle = groupServer - } - state := profile.GetPeerState(stateHandle) - if !set { - state = connections.DISCONNECTED - } + stateHandle := conversationInfo.Handle + if conversationInfo.IsGroup() { + stateHandle = groupServer + } + state := profile.GetPeerState(stateHandle) + if !set { + state = connections.DISCONNECTED + } - blocked := false - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = true - } + blocked := false + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = true + } - // Fetch the message count, and the time of the most recent message - count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) - } + // Fetch the message count, and the time of the most recent message + count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) + } - lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) + lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) - notificationPolicy := constants2.ConversationNotificationPolicyDefault - if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { - notificationPolicy = notificationPolicyAttr - } + notificationPolicy := constants2.ConversationNotificationPolicyDefault + if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { + notificationPolicy = notificationPolicyAttr + } - contacts = append(contacts, Contact{ - Name: name, - Identifier: conversationInfo.ID, - Onion: conversationInfo.Handle, - Status: connections.ConnectionStateName[state], - Picture: cpicPath, - DefaultPicture: defaultPath, - Accepted: conversationInfo.Accepted, - AccessControlList: conversationInfo.ACL, - Blocked: blocked, - SaveHistory: saveHistory, - Messages: count, - Unread: unread, - LastSeenMessageId: lastSeenMessageId, - LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), - IsGroup: conversationInfo.IsGroup(), - GroupServer: groupServer, - IsArchived: isArchived == event.True, - NotificationPolicy: notificationPolicy, - Attributes: conversationInfo.Attributes, - }) - } - } + contacts = append(contacts, Contact{ + Name: name, + Identifier: conversationInfo.ID, + Onion: conversationInfo.Handle, + Status: connections.ConnectionStateName[state], + Picture: cpicPath, + DefaultPicture: defaultPath, + Accepted: conversationInfo.Accepted, + AccessControlList: conversationInfo.ACL, + Blocked: blocked, + SaveHistory: saveHistory, + Messages: count, + Unread: unread, + LastSeenMessageId: lastSeenMessageId, + LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), + IsGroup: conversationInfo.IsGroup(), + GroupServer: groupServer, + IsArchived: isArchived == event.True, + NotificationPolicy: notificationPolicy, + Attributes: conversationInfo.Attributes, + }) + } + } - bytes, _ := json.Marshal(contacts) - e.Data["ContactsJson"] = string(bytes) + bytes, _ := json.Marshal(contacts) + e.Data["ContactsJson"] = string(bytes) - // Marshal the server list into the new peer event... - serversListBytes, _ := json.Marshal(servers) - e.Data[groups.ServerList] = string(serversListBytes) + // Marshal the server list into the new peer event... + serversListBytes, _ := json.Marshal(servers) + e.Data[groups.ServerList] = string(serversListBytes) - log.Debugf("contactsJson %v", e.Data["ContactsJson"]) - } - } + log.Debugf("contactsJson %v", e.Data["ContactsJson"]) + } + } - json, _ := json.Marshal(e) - return string(json) + json, _ := json.Marshal(e) + return string(json) } func GetProfileImage(profile peer.CwtchPeer, conversationInfo *model.Conversation, basepath string) string { - fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) - if err == nil { - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) - // check if the file exists...if it does then set the path... - if _, err := os.Stat(fp); err == nil { - image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) - return image - } - } - } - return RandomProfileImage(conversationInfo.Handle) + fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) + if err == nil { + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) + // check if the file exists...if it does then set the path... + if _, err := os.Stat(fp); err == nil { + image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) + return image + } + } + } + return RandomProfileImage(conversationInfo.Handle) } // handleProfileEvent enriches Profile events so they are usable with out further data fetches func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { - // cache of contact states to use to filter out events repeating known states - var contactStateCache = make(map[string]connections.ConnectionState) + // cache of contact states to use to filter out events repeating known states + var contactStateCache = make(map[string]connections.ConnectionState) - if eh.app == nil { - log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") - } else { - profile := eh.app.GetPeer(ev.Profile) - log.Debugf("New Profile Event to Handle: %v", ev) - switch ev.Event.EventType { - case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } else { - // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... - log.Errorf("todo wait for contact to be added before processing this event...") - return "" - } - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } + if eh.app == nil { + log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") + } else { + profile := eh.app.GetPeer(ev.Profile) + log.Debugf("New Profile Event to Handle: %v", ev) + switch ev.Event.EventType { + case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } else { + // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... + log.Errorf("todo wait for contact to be added before processing this event...") + return "" + } + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } - if ci.Accepted { - handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) - } + if ci.Accepted { + handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) + } - ev.Event.Data["notification"] = string(determineNotification(ci)) - case event.NewMessageFromGroup: - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - } - } - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } + ev.Event.Data["notification"] = string(determineNotification(ci)) + case event.NewMessageFromGroup: + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + } + } + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - if ci != nil && ci.Accepted { - handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) - } + if ci != nil && ci.Accepted { + handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) + } - gci, _ := profile.GetConversationInfo(conversationID) - groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] - state := profile.GetPeerState(groupServer) - // if syncing, don't flood with notifications - if state == connections.SYNCED { - ev.Event.Data["notification"] = string(determineNotification(gci)) - } else { - ev.Event.Data["notification"] = string(constants2.NotificationNone) - } - case event.PeerAcknowledgement: - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - } - case event.ContactCreated: - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - count, err := profile.GetChannelMessageCount(conversationID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationID, err) - } + gci, _ := profile.GetConversationInfo(conversationID) + groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] + state := profile.GetPeerState(groupServer) + // if syncing, don't flood with notifications + if state == connections.SYNCED { + ev.Event.Data["notification"] = string(determineNotification(gci)) + } else { + ev.Event.Data["notification"] = string(constants2.NotificationNone) + } + case event.PeerAcknowledgement: + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + } + case event.ContactCreated: + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + count, err := profile.GetChannelMessageCount(conversationID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationID, err) + } - conversationInfo, err := profile.GetConversationInfo(conversationID) - if err != nil { - log.Errorf("error fetching conversation info for %v %v", conversationID, err) - } + conversationInfo, err := profile.GetConversationInfo(conversationID) + if err != nil { + log.Errorf("error fetching conversation info for %v %v", conversationID, err) + } - blocked := constants.False - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = constants.True - } + blocked := constants.False + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = constants.True + } - accepted := constants.False - if conversationInfo.Accepted { - accepted = constants.True - } + accepted := constants.False + if conversationInfo.Accepted { + accepted = constants.True + } - acl, _ := json.Marshal(conversationInfo.ACL) + acl, _ := json.Marshal(conversationInfo.ACL) - lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) - ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... - ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data["numMessages"] = strconv.Itoa(count) - ev.Event.Data["nick"] = conversationInfo.Handle - ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] - ev.Event.Data["accepted"] = accepted - ev.Event.Data["accessControlList"] = string(acl) - ev.Event.Data["blocked"] = blocked - ev.Event.Data["loading"] = "false" - ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) - case event.GroupCreated: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) - ev.Event.Data[constants2.Picture] = groupPic + lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) + ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... + ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data["numMessages"] = strconv.Itoa(count) + ev.Event.Data["nick"] = conversationInfo.Handle + ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] + ev.Event.Data["accepted"] = accepted + ev.Event.Data["accessControlList"] = string(acl) + ev.Event.Data["blocked"] = blocked + ev.Event.Data["loading"] = "false" + ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) + case event.GroupCreated: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - case event.NewGroup: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - serializedInvite := ev.Event.Data[event.GroupInvite] - if invite, err := model.ValidateInvite(serializedInvite); err == nil { - groupPic := RandomGroupImage(invite.GroupID) - ev.Event.Data[constants2.Picture] = groupPic + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + case event.NewGroup: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + serializedInvite := ev.Event.Data[event.GroupInvite] + if invite, err := model.ValidateInvite(serializedInvite); err == nil { + groupPic := RandomGroupImage(invite.GroupID) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - } else { - log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) - return "" - } - case event.PeerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + } else { + log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) + return "" + } + case event.PeerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) + contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) - if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { - return "" // suppress events from our own profile... - } + if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { + return "" // suppress events from our own profile... + } - // We do not know who this is...don't send any event until we see a message from them - // (at that point the conversation will have been created...) - if contact == nil || err != nil || contact.ID == 0 { - return "" - } + // We do not know who this is...don't send any event until we see a message from them + // (at that point the conversation will have been created...) + if contact == nil || err != nil || contact.ID == 0 { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - if contact != nil { - // No enrichment needed - if cxnState == connections.AUTHENTICATED { - // if known and authed, get vars - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } - case event.ServerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + if contact != nil { + // No enrichment needed + if cxnState == connections.AUTHENTICATED { + // if known and authed, get vars + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } + case event.ServerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - case event.NewRetValMessageFromPeer: - // auto handled event means the setting is already done, we're just deciding if we need to tell the UI - onion := ev.Event.Data[event.RemotePeer] - scope := ev.Event.Data[event.Scope] - path := ev.Event.Data[event.Path] - val := ev.Event.Data[event.Data] - exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) + case event.NewRetValMessageFromPeer: + // auto handled event means the setting is already done, we're just deciding if we need to tell the UI + onion := ev.Event.Data[event.RemotePeer] + scope := ev.Event.Data[event.Scope] + path := ev.Event.Data[event.Path] + val := ev.Event.Data[event.Data] + exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) - conversation, err := profile.FetchConversationInfo(onion) - if err == nil { + conversation, err := profile.FetchConversationInfo(onion) + if err == nil { - if exists && attr.IntoScope(scope) == attr.PublicScope { - zone, path := attr.ParseZone(path) + if exists && attr.IntoScope(scope) == attr.PublicScope { + zone, path := attr.ParseZone(path) - // auto download profile images from contacts... - settings := ReadGlobalSettings() - if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { - fileKey := val - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled && conversation.Accepted { + // auto download profile images from contacts... + settings := ReadGlobalSettings() + if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { + fileKey := val + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if err == nil && imagePreviewsEnabled && conversation.Accepted { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - if _, err := os.Stat(fp); err == nil { - // file is marked as completed downloaded and exists... - return "" - } else { - // the user probably deleted the file, mark completed as false... - profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) - } - } + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + if _, err := os.Stat(fp); err == nil { + // file is marked as completed downloaded and exists... + return "" + } else { + // the user probably deleted the file, mark completed as false... + profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) + } + } - log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) - ev.Event.Data[event.FilePath] = fp - fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) - } else { - // if image previews are disabled then ignore this event... - return "" - } - } - if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { - // we have a locally set override, don't pass this remote set public scope update to UI - return "" - } - } - } - } - } + log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) + ev.Event.Data[event.FilePath] = fp + fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) + } else { + // if image previews are disabled then ignore this event... + return "" + } + } + if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { + // we have a locally set override, don't pass this remote set public scope update to UI + return "" + } + } + } + } + } - json, _ := json.Marshal(unwrap(ev)) - return string(json) + json, _ := json.Marshal(unwrap(ev)) + return string(json) } func unwrap(original *EventProfileEnvelope) *event.Event { - unwrapped := &original.Event - unwrapped.Data["ProfileOnion"] = original.Profile - return unwrapped + unwrapped := &original.Event + unwrapped.Data["ProfileOnion"] = original.Profile + return unwrapped } func (eh *EventHandler) startHandlingPeer(onion string) { - eventBus := eh.app.GetEventBus(onion) - q := event.NewQueue() + eventBus := eh.app.GetEventBus(onion) + q := event.NewQueue() - eventBus.Subscribe(event.NetworkStatus, q) - eventBus.Subscribe(event.ACNInfo, q) - eventBus.Subscribe(event.NewMessageFromPeer, q) - eventBus.Subscribe(event.UpdatedProfileAttribute, q) - eventBus.Subscribe(event.PeerAcknowledgement, q) - eventBus.Subscribe(event.DeleteContact, q) - eventBus.Subscribe(event.AppError, q) - eventBus.Subscribe(event.IndexedAcknowledgement, q) - eventBus.Subscribe(event.IndexedFailure, q) - eventBus.Subscribe(event.ContactCreated, q) - eventBus.Subscribe(event.NewMessageFromGroup, q) - eventBus.Subscribe(event.GroupCreated, q) - eventBus.Subscribe(event.NewGroup, q) - eventBus.Subscribe(event.ServerStateChange, q) - eventBus.Subscribe(event.PeerStateChange, q) - eventBus.Subscribe(event.NewRetValMessageFromPeer, q) - eventBus.Subscribe(event.ShareManifest, q) - eventBus.Subscribe(event.ManifestSizeReceived, q) - eventBus.Subscribe(event.ManifestError, q) - eventBus.Subscribe(event.ManifestReceived, q) - eventBus.Subscribe(event.ManifestSaved, q) - eventBus.Subscribe(event.FileDownloadProgressUpdate, q) - eventBus.Subscribe(event.FileDownloaded, q) + eventBus.Subscribe(event.NetworkStatus, q) + eventBus.Subscribe(event.ACNInfo, q) + eventBus.Subscribe(event.NewMessageFromPeer, q) + eventBus.Subscribe(event.UpdatedProfileAttribute, q) + eventBus.Subscribe(event.PeerAcknowledgement, q) + eventBus.Subscribe(event.DeleteContact, q) + eventBus.Subscribe(event.AppError, q) + eventBus.Subscribe(event.IndexedAcknowledgement, q) + eventBus.Subscribe(event.IndexedFailure, q) + eventBus.Subscribe(event.ContactCreated, q) + eventBus.Subscribe(event.NewMessageFromGroup, q) + eventBus.Subscribe(event.GroupCreated, q) + eventBus.Subscribe(event.NewGroup, q) + eventBus.Subscribe(event.ServerStateChange, q) + eventBus.Subscribe(event.PeerStateChange, q) + eventBus.Subscribe(event.NewRetValMessageFromPeer, q) + eventBus.Subscribe(event.ShareManifest, q) + eventBus.Subscribe(event.ManifestSizeReceived, q) + eventBus.Subscribe(event.ManifestError, q) + eventBus.Subscribe(event.ManifestReceived, q) + eventBus.Subscribe(event.ManifestSaved, q) + eventBus.Subscribe(event.FileDownloadProgressUpdate, q) + eventBus.Subscribe(event.FileDownloaded, q) - go eh.forwardProfileMessages(onion, q) + go eh.forwardProfileMessages(onion, q) } func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) { - log.Infof("Launching Forwarding Goroutine") - // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine - for { - e := q.Next() - ev := EventProfileEnvelope{Event: e, Profile: onion} - eh.profileEvents <- ev - if ev.Event.EventType == event.Shutdown { - return - } - } + log.Infof("Launching Forwarding Goroutine") + // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine + for { + e := q.Next() + ev := EventProfileEnvelope{Event: e, Profile: onion} + eh.profileEvents <- ev + if ev.Event.EventType == event.Shutdown { + return + } + } } // Push pushes an event onto the app event bus // It is also a way for libCwtch-go to publish an event for consumption by a UI before a Cwtch app has been initialized // use: to signal an error before a cwtch app could be created func (eh *EventHandler) Push(newEvent event.Event) { - eh.appBusQueue.Publish(newEvent) + eh.appBusQueue.Publish(newEvent) } func getLastMessageTime(conversationMessages []model.ConversationMessage) int { - if len(conversationMessages) == 0 { - return 0 - } - time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) - if err != nil { - return 0 - } - return int(time.Unix()) + if len(conversationMessages) == 0 { + return 0 + } + time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) + if err != nil { + return 0 + } + return int(time.Unix()) } // handleImagePreviews checks settings and, if appropriate, auto-downloads any images func handleImagePreviews(profile peer.CwtchPeer, ev *event.Event, conversationID, senderID int) { - settings := ReadGlobalSettings() - fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled { - var cm model.MessageWrapper - err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) - if err == nil && cm.Overlay == model.OverlayFileSharing { - var fm filesharing.OverlayMessage - err = json.Unmarshal([]byte(cm.Data), &fm) - if err == nil { - if fm.ShouldAutoDL() { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) - log.Debugf("autodownloading file!") - ev.Data["Auto"] = constants.True - mID, _ := strconv.Atoi(ev.Data["Index"]) - profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) - fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) - } - } - } - } + settings := ReadGlobalSettings() + fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) + + // Don't autodownload images if the download path does not exist. + if settings.DownloadPath == "" { + return + } + if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { + return + } + + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if err == nil && imagePreviewsEnabled { + var cm model.MessageWrapper + err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) + if err == nil && cm.Overlay == model.OverlayFileSharing { + var fm filesharing.OverlayMessage + err = json.Unmarshal([]byte(cm.Data), &fm) + if err == nil { + if fm.ShouldAutoDL() { + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) + log.Debugf("autodownloading file!") + ev.Data["Auto"] = constants.True + mID, _ := strconv.Atoi(ev.Data["Index"]) + profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) + fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) + } + } + } + } } From 085b414bd8c4f69d658f94a531f8861ea202bb82 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 26 Aug 2022 10:46:42 -0700 Subject: [PATCH 2/4] Don't autodownload images if download folder doesn't exist --- go.mod | 6 +- go.sum | 287 ++++++++++- utils/eventHandler.go | 1091 +++++++++++++++++++++-------------------- 3 files changed, 831 insertions(+), 553 deletions(-) diff --git a/go.mod b/go.mod index 1d7bedf..6e511ab 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go -go 1.18 +go 1.17 require ( - cwtch.im/cwtch v0.17.1 + cwtch.im/cwtch v0.17.2 git.openprivacy.ca/cwtch.im/server v1.4.2 git.openprivacy.ca/openprivacy/connectivity v1.8.5 git.openprivacy.ca/openprivacy/log v1.0.3 @@ -23,5 +23,3 @@ require ( golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a // indirect golang.org/x/text v0.3.7 // indirect ) - - diff --git a/go.sum b/go.sum index 6af1fe6..19940be 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,19 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cwtch.im/cwtch v0.14.9/go.mod h1:/fLuoYLY/7JHw6RojFojpd245CiOcU24QpWqzh9FRDI= +cwtch.im/cwtch v0.17.2 h1:Bn/JilRNVzINfB43G8/OUHayZ8fw/YJDQGjGTi/2IEg= +cwtch.im/cwtch v0.17.2/go.mod h1:ugyLEZrlOIiKi1/QNQRhO12IvZy8lekJSz0mD2EVVlQ= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= git.openprivacy.ca/cwtch.im/server v1.4.2 h1:ZcRK1XuWvJzNjYdAvAISD8HcEITPwWbvRiIZGkMKu1k= @@ -9,23 +25,64 @@ git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGy git.openprivacy.ca/openprivacy/bine v0.0.4/go.mod h1:13ZqhKyqakDsN/ZkQkIGNULsmLyqtXc46XBcnuXm/mU= git.openprivacy.ca/openprivacy/connectivity v1.5.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw= git.openprivacy.ca/openprivacy/connectivity v1.8.3/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw= -git.openprivacy.ca/openprivacy/connectivity v1.8.4 h1:fQIOtvtCtZpB1D2XvmSJUdb8aqSKujPsqMHWXl52150= -git.openprivacy.ca/openprivacy/connectivity v1.8.4/go.mod h1:pG50Dq4IelxFGyF1y8dU5kXrnsDGEnobbEFZlB9COLM= git.openprivacy.ca/openprivacy/connectivity v1.8.5 h1:eAlpNyxMBVq/PK+5EkG3zpcCjRjxi6Sg+iVoamuX1co= git.openprivacy.ca/openprivacy/connectivity v1.8.5/go.mod h1:pG50Dq4IelxFGyF1y8dU5kXrnsDGEnobbEFZlB9COLM= git.openprivacy.ca/openprivacy/log v1.0.2/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= git.openprivacy.ca/openprivacy/log v1.0.3 h1:E/PMm4LY+Q9s3aDpfySfEDq/vYQontlvNj/scrPaga0= git.openprivacy.ca/openprivacy/log v1.0.3/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cucumber/gherkin-go/v19 v19.0.3/go.mod h1:jY/NP6jUtRSArQQJ5h1FXOUgk5fZK24qtE7vKi776Vw= +github.com/cucumber/godog v0.12.0/go.mod h1:u6SD7IXC49dLpPN35kal0oYEjsXZWee4pW6Tm9t5pIc= +github.com/cucumber/messages-go/v16 v16.0.0/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= +github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -34,57 +91,203 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc= github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-memdb v1.3.0/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA= github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG9WsDpiCvZf1yKO7sz7scAjSlBa0= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mutecomm/go-sqlcipher/v4 v4.4.2 h1:eM10bFtI4UvibIsKr10/QT7Yfz+NADfjZYh0GKrXUNc= github.com/mutecomm/go-sqlcipher/v4 v4.4.2/go.mod h1:mF2UmIpBnzFeBdu/ypTDb/LdbS0nk0dfSN1WUsWTjMA= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.0.0-rc2 h1:2ukZwTHG/SAlJe4mm5xTdcUYH7IRvldIXhukE1pQBeY= github.com/onsi/ginkgo/v2 v2.0.0-rc2/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -93,12 +296,29 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -110,22 +330,64 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a h1:ppl5mZgokTT8uPkmYOyEUmPTr3ypaKkg5eFOGrAmxxE= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -134,14 +396,29 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 40f410d..db60e0c 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -1,666 +1,669 @@ package utils import ( - "encoding/json" - "fmt" - "os" - "strconv" + "encoding/json" + "fmt" + "os" + "strconv" - "cwtch.im/cwtch/app" - "cwtch.im/cwtch/app/plugins" - "cwtch.im/cwtch/model" - "cwtch.im/cwtch/model/attr" - "cwtch.im/cwtch/model/constants" - "cwtch.im/cwtch/peer" - "cwtch.im/cwtch/protocol/connections" - constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" - "git.openprivacy.ca/openprivacy/log" + "cwtch.im/cwtch/app" + "cwtch.im/cwtch/app/plugins" + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/model/constants" + "cwtch.im/cwtch/peer" + "cwtch.im/cwtch/protocol/connections" + constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" + "git.openprivacy.ca/openprivacy/log" - "time" + "time" - "cwtch.im/cwtch/event" - "cwtch.im/cwtch/functionality/filesharing" + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/functionality/filesharing" ) type EventProfileEnvelope struct { - Event event.Event - Profile string + Event event.Event + Profile string } type EventHandler struct { - app app.Application - appBusQueue event.Queue - profileEvents chan EventProfileEnvelope + app app.Application + appBusQueue event.Queue + profileEvents chan EventProfileEnvelope } // We should be reading from profile events pretty quickly, but we make this buffer fairly large... const profileEventsBufferSize = 512 func NewEventHandler() *EventHandler { - eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} - return eh + eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} + return eh } func (eh *EventHandler) HandleApp(application app.Application) { - eh.app = application - application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) + eh.app = application + application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) } func (eh *EventHandler) GetNextEvent() string { - appChan := eh.appBusQueue.OutChan() + appChan := eh.appBusQueue.OutChan() - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - default: - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - case ev := <-eh.profileEvents: - return eh.handleProfileEvent(&ev) - } - } + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + default: + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + case ev := <-eh.profileEvents: + return eh.handleProfileEvent(&ev) + } + } } // handleAppBusEvent enriches AppBus events so they are usable with out further data fetches func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { - if eh.app != nil { - switch e.EventType { - case event.ACNStatus: - if e.Data[event.Progress] == "100" { - for _, onion := range eh.app.ListProfiles() { - // launch a listen thread (internally this does a check that the protocol engine is not listening) - // and as such is safe to call. - eh.app.GetPeer(onion).Listen() - } - } - case event.NewPeer: - onion := e.Data[event.Identity] - profile := eh.app.GetPeer(e.Data[event.Identity]) - if profile == nil { - log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") - break - } - log.Debug("New Peer Event: %v", e) + if eh.app != nil { + switch e.EventType { + case event.ACNStatus: + if e.Data[event.Progress] == "100" { + for _, onion := range eh.app.ListProfiles() { + // launch a listen thread (internally this does a check that the protocol engine is not listening) + // and as such is safe to call. + eh.app.GetPeer(onion).Listen() + } + } + case event.NewPeer: + onion := e.Data[event.Identity] + profile := eh.app.GetPeer(e.Data[event.Identity]) + if profile == nil { + log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") + break + } + log.Debug("New Peer Event: %v", e) - if e.Data["Reload"] != event.True { - eh.startHandlingPeer(onion) - } + if e.Data["Reload"] != event.True { + eh.startHandlingPeer(onion) + } - // CwtchPeer will always set this now... - tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) - e.Data[constants.Tag] = tag + // CwtchPeer will always set this now... + tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) + e.Data[constants.Tag] = tag - if e.Data[event.Created] == event.True { - profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) - } + if e.Data[event.Created] == event.True { + profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) + } - profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) - eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) - eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) + profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) + eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) + eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) - // If the user has chosen to block unknown profiles - // then explicitly configure the protocol engine to do so.. - settings := ReadGlobalSettings() - if settings.BlockUnknownConnections { - profile.BlockUnknownConnections() - } else { - // For completeness - profile.AllowUnknownConnections() - } + // If the user has chosen to block unknown profiles + // then explicitly configure the protocol engine to do so.. + settings := ReadGlobalSettings() + if settings.BlockUnknownConnections { + profile.BlockUnknownConnections() + } else { + // For completeness + profile.AllowUnknownConnections() + } - // Start up the Profile - profile.Listen() - profile.StartPeersConnections() - if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { - profile.StartServerConnections() - } + // Start up the Profile + profile.Listen() + profile.StartPeersConnections() + if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { + profile.StartServerConnections() + } - online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) - // Name always exists - e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) - // if a custom profile image exists then default to it. - key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - if !exists { - e.Data[constants2.Picture] = RandomProfileImage(onion) - } else { - e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) - serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) - profile.ShareFile(key, serializedManifest) - log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) - } + online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) + // Name always exists + e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) + // if a custom profile image exists then default to it. + key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + if !exists { + e.Data[constants2.Picture] = RandomProfileImage(onion) + } else { + e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) + serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) + profile.ShareFile(key, serializedManifest) + log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) + } - // Resolve the profile image of the profile. + // Resolve the profile image of the profile. - e.Data["Online"] = online + e.Data["Online"] = online - // If file sharing is enabled then reshare all active files... - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - if err == nil { - fsf.ReShareFiles(profile) - } + // If file sharing is enabled then reshare all active files... + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + if err == nil { + fsf.ReShareFiles(profile) + } - // Construct our conversations and our srever lists - var contacts []Contact - var servers []groups.Server + // Construct our conversations and our srever lists + var contacts []Contact + var servers []groups.Server - conversations, err := profile.FetchConversations() + conversations, err := profile.FetchConversations() - if err == nil { - // We have conversations attached to this profile... - for _, conversationInfo := range conversations { - // Only compile the server info if we have enabled the experiment... - // Note that this means that this info can become stale if when first loaded the experiment - // has been disabled and then is later re-enabled. As such we need to ensure that this list is - // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... - if conversationInfo.IsServer() { - groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) - if err == nil { - servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) - } - continue - } + if err == nil { + // We have conversations attached to this profile... + for _, conversationInfo := range conversations { + // Only compile the server info if we have enabled the experiment... + // Note that this means that this info can become stale if when first loaded the experiment + // has been disabled and then is later re-enabled. As such we need to ensure that this list is + // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... + if conversationInfo.IsServer() { + groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) + if err == nil { + servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) + } + continue + } - // Prefer local override to public name... - name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - name = conversationInfo.Handle - } - } + // Prefer local override to public name... + name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + name = conversationInfo.Handle + } + } - // Resolve the profile image of the contact - var cpicPath string - var defaultPath string - if conversationInfo.IsGroup() { - cpicPath = RandomGroupImage(conversationInfo.Handle) - defaultPath = RandomGroupImage(conversationInfo.Handle) - } else { - cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) - defaultPath = RandomProfileImage(conversationInfo.Handle) - } + // Resolve the profile image of the contact + var cpicPath string + var defaultPath string + if conversationInfo.IsGroup() { + cpicPath = RandomGroupImage(conversationInfo.Handle) + defaultPath = RandomGroupImage(conversationInfo.Handle) + } else { + cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) + defaultPath = RandomProfileImage(conversationInfo.Handle) + } - // Resolve Save History Setting - saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) - if !set { - saveHistory = event.DeleteHistoryDefault - } + // Resolve Save History Setting + saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) + if !set { + saveHistory = event.DeleteHistoryDefault + } - // Resolve Archived Setting - isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) - if !set { - isArchived = event.False - } + // Resolve Archived Setting + isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) + if !set { + isArchived = event.False + } - unread := 0 - lastSeenMessageId := -1 - lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) - if set { - lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) - if err == nil { - // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) - messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) - if err == nil { - for _, message := range messages { - msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) - if err == nil { - if msgTime.UTC().After(lastSeenTime.UTC()) { - unread++ - } else { - lastSeenMessageId = message.ID - break - } - } - } - } - } - } + unread := 0 + lastSeenMessageId := -1 + lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) + if set { + lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) + if err == nil { + // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) + messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) + if err == nil { + for _, message := range messages { + msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) + if err == nil { + if msgTime.UTC().After(lastSeenTime.UTC()) { + unread++ + } else { + lastSeenMessageId = message.ID + break + } + } + } + } + } + } - groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) + groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) - stateHandle := conversationInfo.Handle - if conversationInfo.IsGroup() { - stateHandle = groupServer - } - state := profile.GetPeerState(stateHandle) - if !set { - state = connections.DISCONNECTED - } + stateHandle := conversationInfo.Handle + if conversationInfo.IsGroup() { + stateHandle = groupServer + } + state := profile.GetPeerState(stateHandle) + if !set { + state = connections.DISCONNECTED + } - blocked := false - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = true - } + blocked := false + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = true + } - // Fetch the message count, and the time of the most recent message - count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) - } + // Fetch the message count, and the time of the most recent message + count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) + } - lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) + lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) - notificationPolicy := constants2.ConversationNotificationPolicyDefault - if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { - notificationPolicy = notificationPolicyAttr - } + notificationPolicy := constants2.ConversationNotificationPolicyDefault + if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { + notificationPolicy = notificationPolicyAttr + } - contacts = append(contacts, Contact{ - Name: name, - Identifier: conversationInfo.ID, - Onion: conversationInfo.Handle, - Status: connections.ConnectionStateName[state], - Picture: cpicPath, - DefaultPicture: defaultPath, - Accepted: conversationInfo.Accepted, - AccessControlList: conversationInfo.ACL, - Blocked: blocked, - SaveHistory: saveHistory, - Messages: count, - Unread: unread, - LastSeenMessageId: lastSeenMessageId, - LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), - IsGroup: conversationInfo.IsGroup(), - GroupServer: groupServer, - IsArchived: isArchived == event.True, - NotificationPolicy: notificationPolicy, - Attributes: conversationInfo.Attributes, - }) - } - } + contacts = append(contacts, Contact{ + Name: name, + Identifier: conversationInfo.ID, + Onion: conversationInfo.Handle, + Status: connections.ConnectionStateName[state], + Picture: cpicPath, + DefaultPicture: defaultPath, + Accepted: conversationInfo.Accepted, + AccessControlList: conversationInfo.ACL, + Blocked: blocked, + SaveHistory: saveHistory, + Messages: count, + Unread: unread, + LastSeenMessageId: lastSeenMessageId, + LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), + IsGroup: conversationInfo.IsGroup(), + GroupServer: groupServer, + IsArchived: isArchived == event.True, + NotificationPolicy: notificationPolicy, + Attributes: conversationInfo.Attributes, + }) + } + } - bytes, _ := json.Marshal(contacts) - e.Data["ContactsJson"] = string(bytes) + bytes, _ := json.Marshal(contacts) + e.Data["ContactsJson"] = string(bytes) - // Marshal the server list into the new peer event... - serversListBytes, _ := json.Marshal(servers) - e.Data[groups.ServerList] = string(serversListBytes) + // Marshal the server list into the new peer event... + serversListBytes, _ := json.Marshal(servers) + e.Data[groups.ServerList] = string(serversListBytes) - log.Debugf("contactsJson %v", e.Data["ContactsJson"]) - } - } + log.Debugf("contactsJson %v", e.Data["ContactsJson"]) + } + } - json, _ := json.Marshal(e) - return string(json) + json, _ := json.Marshal(e) + return string(json) } func GetProfileImage(profile peer.CwtchPeer, conversationInfo *model.Conversation, basepath string) string { - fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) - if err == nil { - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) - // check if the file exists...if it does then set the path... - if _, err := os.Stat(fp); err == nil { - image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) - return image - } - } - } - return RandomProfileImage(conversationInfo.Handle) + fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) + if err == nil { + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) + // check if the file exists...if it does then set the path... + if _, err := os.Stat(fp); err == nil { + image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) + return image + } + } + } + return RandomProfileImage(conversationInfo.Handle) } // handleProfileEvent enriches Profile events so they are usable with out further data fetches func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { - // cache of contact states to use to filter out events repeating known states - var contactStateCache = make(map[string]connections.ConnectionState) + // cache of contact states to use to filter out events repeating known states + var contactStateCache = make(map[string]connections.ConnectionState) - if eh.app == nil { - log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") - } else { - profile := eh.app.GetPeer(ev.Profile) - log.Debugf("New Profile Event to Handle: %v", ev) - switch ev.Event.EventType { - case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } else { - // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... - log.Errorf("todo wait for contact to be added before processing this event...") - return "" - } - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } + if eh.app == nil { + log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") + } else { + profile := eh.app.GetPeer(ev.Profile) + log.Debugf("New Profile Event to Handle: %v", ev) + switch ev.Event.EventType { + case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } else { + // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... + log.Errorf("todo wait for contact to be added before processing this event...") + return "" + } + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } - if ci.Accepted { - handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) - } + if ci.Accepted { + handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) + } - ev.Event.Data["notification"] = string(determineNotification(ci)) - case event.NewMessageFromGroup: - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - } - } - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } + ev.Event.Data["notification"] = string(determineNotification(ci)) + case event.NewMessageFromGroup: + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + } + } + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - if ci != nil && ci.Accepted { - handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) - } + if ci != nil && ci.Accepted { + handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) + } - gci, _ := profile.GetConversationInfo(conversationID) - groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] - state := profile.GetPeerState(groupServer) - // if syncing, don't flood with notifications - if state == connections.SYNCED { - ev.Event.Data["notification"] = string(determineNotification(gci)) - } else { - ev.Event.Data["notification"] = string(constants2.NotificationNone) - } - case event.PeerAcknowledgement: - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - } - case event.ContactCreated: - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - count, err := profile.GetChannelMessageCount(conversationID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationID, err) - } + gci, _ := profile.GetConversationInfo(conversationID) + groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] + state := profile.GetPeerState(groupServer) + // if syncing, don't flood with notifications + if state == connections.SYNCED { + ev.Event.Data["notification"] = string(determineNotification(gci)) + } else { + ev.Event.Data["notification"] = string(constants2.NotificationNone) + } + case event.PeerAcknowledgement: + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + } + case event.ContactCreated: + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + count, err := profile.GetChannelMessageCount(conversationID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationID, err) + } - conversationInfo, err := profile.GetConversationInfo(conversationID) - if err != nil { - log.Errorf("error fetching conversation info for %v %v", conversationID, err) - } + conversationInfo, err := profile.GetConversationInfo(conversationID) + if err != nil { + log.Errorf("error fetching conversation info for %v %v", conversationID, err) + } - blocked := constants.False - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = constants.True - } + blocked := constants.False + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = constants.True + } - accepted := constants.False - if conversationInfo.Accepted { - accepted = constants.True - } + accepted := constants.False + if conversationInfo.Accepted { + accepted = constants.True + } - acl, _ := json.Marshal(conversationInfo.ACL) + acl, _ := json.Marshal(conversationInfo.ACL) - lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) - ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... - ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data["numMessages"] = strconv.Itoa(count) - ev.Event.Data["nick"] = conversationInfo.Handle - ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] - ev.Event.Data["accepted"] = accepted - ev.Event.Data["accessControlList"] = string(acl) - ev.Event.Data["blocked"] = blocked - ev.Event.Data["loading"] = "false" - ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) - case event.GroupCreated: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) - ev.Event.Data[constants2.Picture] = groupPic + lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) + ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... + ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data["numMessages"] = strconv.Itoa(count) + ev.Event.Data["nick"] = conversationInfo.Handle + ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] + ev.Event.Data["accepted"] = accepted + ev.Event.Data["accessControlList"] = string(acl) + ev.Event.Data["blocked"] = blocked + ev.Event.Data["loading"] = "false" + ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) + case event.GroupCreated: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - case event.NewGroup: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - serializedInvite := ev.Event.Data[event.GroupInvite] - if invite, err := model.ValidateInvite(serializedInvite); err == nil { - groupPic := RandomGroupImage(invite.GroupID) - ev.Event.Data[constants2.Picture] = groupPic + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + case event.NewGroup: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + serializedInvite := ev.Event.Data[event.GroupInvite] + if invite, err := model.ValidateInvite(serializedInvite); err == nil { + groupPic := RandomGroupImage(invite.GroupID) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - } else { - log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) - return "" - } - case event.PeerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + } else { + log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) + return "" + } + case event.PeerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) + contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) - if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { - return "" // suppress events from our own profile... - } + if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { + return "" // suppress events from our own profile... + } - // We do not know who this is...don't send any event until we see a message from them - // (at that point the conversation will have been created...) - if contact == nil || err != nil || contact.ID == 0 { - return "" - } + // We do not know who this is...don't send any event until we see a message from them + // (at that point the conversation will have been created...) + if contact == nil || err != nil || contact.ID == 0 { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - if contact != nil { - // No enrichment needed - if cxnState == connections.AUTHENTICATED { - // if known and authed, get vars - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } - case event.ServerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + if contact != nil { + // No enrichment needed + if cxnState == connections.AUTHENTICATED { + // if known and authed, get vars + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } + case event.ServerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - case event.NewRetValMessageFromPeer: - // auto handled event means the setting is already done, we're just deciding if we need to tell the UI - onion := ev.Event.Data[event.RemotePeer] - scope := ev.Event.Data[event.Scope] - path := ev.Event.Data[event.Path] - val := ev.Event.Data[event.Data] - exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) + case event.NewRetValMessageFromPeer: + // auto handled event means the setting is already done, we're just deciding if we need to tell the UI + onion := ev.Event.Data[event.RemotePeer] + scope := ev.Event.Data[event.Scope] + path := ev.Event.Data[event.Path] + val := ev.Event.Data[event.Data] + exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) - conversation, err := profile.FetchConversationInfo(onion) - if err == nil { + conversation, err := profile.FetchConversationInfo(onion) + if err == nil { - if exists && attr.IntoScope(scope) == attr.PublicScope { - zone, path := attr.ParseZone(path) + if exists && attr.IntoScope(scope) == attr.PublicScope { + zone, path := attr.ParseZone(path) - // auto download profile images from contacts... - settings := ReadGlobalSettings() - if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { - fileKey := val - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled && conversation.Accepted { + // auto download profile images from contacts... + settings := ReadGlobalSettings() + if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { + fileKey := val + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if err == nil && imagePreviewsEnabled && conversation.Accepted { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - if _, err := os.Stat(fp); err == nil { - // file is marked as completed downloaded and exists... - return "" - } else { - // the user probably deleted the file, mark completed as false... - profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) - } - } + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + if _, err := os.Stat(fp); err == nil { + // file is marked as completed downloaded and exists... + return "" + } else { + // the user probably deleted the file, mark completed as false... + profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) + } + } - log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) - ev.Event.Data[event.FilePath] = fp - fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) - } else { - // if image previews are disabled then ignore this event... - return "" - } - } - if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { - // we have a locally set override, don't pass this remote set public scope update to UI - return "" - } - } - } - } - } + log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) + ev.Event.Data[event.FilePath] = fp + fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) + } else { + // if image previews are disabled then ignore this event... + return "" + } + } + if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { + // we have a locally set override, don't pass this remote set public scope update to UI + return "" + } + } + } + } + } - json, _ := json.Marshal(unwrap(ev)) - return string(json) + json, _ := json.Marshal(unwrap(ev)) + return string(json) } func unwrap(original *EventProfileEnvelope) *event.Event { - unwrapped := &original.Event - unwrapped.Data["ProfileOnion"] = original.Profile - return unwrapped + unwrapped := &original.Event + unwrapped.Data["ProfileOnion"] = original.Profile + return unwrapped } func (eh *EventHandler) startHandlingPeer(onion string) { - eventBus := eh.app.GetEventBus(onion) - q := event.NewQueue() + eventBus := eh.app.GetEventBus(onion) + q := event.NewQueue() - eventBus.Subscribe(event.NetworkStatus, q) - eventBus.Subscribe(event.ACNInfo, q) - eventBus.Subscribe(event.NewMessageFromPeer, q) - eventBus.Subscribe(event.UpdatedProfileAttribute, q) - eventBus.Subscribe(event.PeerAcknowledgement, q) - eventBus.Subscribe(event.DeleteContact, q) - eventBus.Subscribe(event.AppError, q) - eventBus.Subscribe(event.IndexedAcknowledgement, q) - eventBus.Subscribe(event.IndexedFailure, q) - eventBus.Subscribe(event.ContactCreated, q) - eventBus.Subscribe(event.NewMessageFromGroup, q) - eventBus.Subscribe(event.GroupCreated, q) - eventBus.Subscribe(event.NewGroup, q) - eventBus.Subscribe(event.ServerStateChange, q) - eventBus.Subscribe(event.PeerStateChange, q) - eventBus.Subscribe(event.NewRetValMessageFromPeer, q) - eventBus.Subscribe(event.ShareManifest, q) - eventBus.Subscribe(event.ManifestSizeReceived, q) - eventBus.Subscribe(event.ManifestError, q) - eventBus.Subscribe(event.ManifestReceived, q) - eventBus.Subscribe(event.ManifestSaved, q) - eventBus.Subscribe(event.FileDownloadProgressUpdate, q) - eventBus.Subscribe(event.FileDownloaded, q) + eventBus.Subscribe(event.NetworkStatus, q) + eventBus.Subscribe(event.ACNInfo, q) + eventBus.Subscribe(event.NewMessageFromPeer, q) + eventBus.Subscribe(event.UpdatedProfileAttribute, q) + eventBus.Subscribe(event.PeerAcknowledgement, q) + eventBus.Subscribe(event.DeleteContact, q) + eventBus.Subscribe(event.AppError, q) + eventBus.Subscribe(event.IndexedAcknowledgement, q) + eventBus.Subscribe(event.IndexedFailure, q) + eventBus.Subscribe(event.ContactCreated, q) + eventBus.Subscribe(event.NewMessageFromGroup, q) + eventBus.Subscribe(event.GroupCreated, q) + eventBus.Subscribe(event.NewGroup, q) + eventBus.Subscribe(event.ServerStateChange, q) + eventBus.Subscribe(event.PeerStateChange, q) + eventBus.Subscribe(event.NewRetValMessageFromPeer, q) + eventBus.Subscribe(event.ShareManifest, q) + eventBus.Subscribe(event.ManifestSizeReceived, q) + eventBus.Subscribe(event.ManifestError, q) + eventBus.Subscribe(event.ManifestReceived, q) + eventBus.Subscribe(event.ManifestSaved, q) + eventBus.Subscribe(event.FileDownloadProgressUpdate, q) + eventBus.Subscribe(event.FileDownloaded, q) - go eh.forwardProfileMessages(onion, q) + go eh.forwardProfileMessages(onion, q) } func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) { - log.Infof("Launching Forwarding Goroutine") - // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine - for { - e := q.Next() - ev := EventProfileEnvelope{Event: e, Profile: onion} - eh.profileEvents <- ev - if ev.Event.EventType == event.Shutdown { - return - } - } + log.Infof("Launching Forwarding Goroutine") + // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine + for { + e := q.Next() + ev := EventProfileEnvelope{Event: e, Profile: onion} + eh.profileEvents <- ev + if ev.Event.EventType == event.Shutdown { + return + } + } } // Push pushes an event onto the app event bus // It is also a way for libCwtch-go to publish an event for consumption by a UI before a Cwtch app has been initialized // use: to signal an error before a cwtch app could be created func (eh *EventHandler) Push(newEvent event.Event) { - eh.appBusQueue.Publish(newEvent) + eh.appBusQueue.Publish(newEvent) } func getLastMessageTime(conversationMessages []model.ConversationMessage) int { - if len(conversationMessages) == 0 { - return 0 - } - time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) - if err != nil { - return 0 - } - return int(time.Unix()) + if len(conversationMessages) == 0 { + return 0 + } + time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) + if err != nil { + return 0 + } + return int(time.Unix()) } // handleImagePreviews checks settings and, if appropriate, auto-downloads any images func handleImagePreviews(profile peer.CwtchPeer, ev *event.Event, conversationID, senderID int) { - settings := ReadGlobalSettings() - fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) + settings := ReadGlobalSettings() + fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) - // Don't autodownload images if the download path does not exist. - if settings.DownloadPath == "" { - return - } - if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { - return - } + // Short-circuit failures + // Don't autodownload images if the download path does not exist. + if settings.DownloadPath == "" { + return + } - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled { - var cm model.MessageWrapper - err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) - if err == nil && cm.Overlay == model.OverlayFileSharing { - var fm filesharing.OverlayMessage - err = json.Unmarshal([]byte(cm.Data), &fm) - if err == nil { - if fm.ShouldAutoDL() { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) - log.Debugf("autodownloading file!") - ev.Data["Auto"] = constants.True - mID, _ := strconv.Atoi(ev.Data["Index"]) - profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) - fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) - } - } - } - } + // Don't autodownload images if the download path does not exist. + if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { + return + } + + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if err == nil && imagePreviewsEnabled { + var cm model.MessageWrapper + err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) + if err == nil && cm.Overlay == model.OverlayFileSharing { + var fm filesharing.OverlayMessage + err = json.Unmarshal([]byte(cm.Data), &fm) + if err == nil { + if fm.ShouldAutoDL() { + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) + log.Debugf("autodownloading file!") + ev.Data["Auto"] = constants.True + mID, _ := strconv.Atoi(ev.Data["Index"]) + profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) + fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) + } + } + } + } } From 2058a5157922af2048ab39356b5fcaf3ac614521 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 26 Aug 2022 10:57:35 -0700 Subject: [PATCH 3/4] Don't shadow file sharing functionality error --- utils/eventHandler.go | 1098 +++++++++++++++++++++-------------------- 1 file changed, 552 insertions(+), 546 deletions(-) diff --git a/utils/eventHandler.go b/utils/eventHandler.go index db60e0c..f9f5676 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -1,669 +1,675 @@ package utils import ( - "encoding/json" - "fmt" - "os" - "strconv" + "encoding/json" + "fmt" + "os" + "strconv" - "cwtch.im/cwtch/app" - "cwtch.im/cwtch/app/plugins" - "cwtch.im/cwtch/model" - "cwtch.im/cwtch/model/attr" - "cwtch.im/cwtch/model/constants" - "cwtch.im/cwtch/peer" - "cwtch.im/cwtch/protocol/connections" - constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" - "git.openprivacy.ca/openprivacy/log" + "cwtch.im/cwtch/app" + "cwtch.im/cwtch/app/plugins" + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/model/constants" + "cwtch.im/cwtch/peer" + "cwtch.im/cwtch/protocol/connections" + constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" + "git.openprivacy.ca/openprivacy/log" - "time" + "time" - "cwtch.im/cwtch/event" - "cwtch.im/cwtch/functionality/filesharing" + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/functionality/filesharing" ) type EventProfileEnvelope struct { - Event event.Event - Profile string + Event event.Event + Profile string } type EventHandler struct { - app app.Application - appBusQueue event.Queue - profileEvents chan EventProfileEnvelope + app app.Application + appBusQueue event.Queue + profileEvents chan EventProfileEnvelope } // We should be reading from profile events pretty quickly, but we make this buffer fairly large... const profileEventsBufferSize = 512 func NewEventHandler() *EventHandler { - eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} - return eh + eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} + return eh } func (eh *EventHandler) HandleApp(application app.Application) { - eh.app = application - application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) + eh.app = application + application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) } func (eh *EventHandler) GetNextEvent() string { - appChan := eh.appBusQueue.OutChan() + appChan := eh.appBusQueue.OutChan() - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - default: - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - case ev := <-eh.profileEvents: - return eh.handleProfileEvent(&ev) - } - } + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + default: + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + case ev := <-eh.profileEvents: + return eh.handleProfileEvent(&ev) + } + } } // handleAppBusEvent enriches AppBus events so they are usable with out further data fetches func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { - if eh.app != nil { - switch e.EventType { - case event.ACNStatus: - if e.Data[event.Progress] == "100" { - for _, onion := range eh.app.ListProfiles() { - // launch a listen thread (internally this does a check that the protocol engine is not listening) - // and as such is safe to call. - eh.app.GetPeer(onion).Listen() - } - } - case event.NewPeer: - onion := e.Data[event.Identity] - profile := eh.app.GetPeer(e.Data[event.Identity]) - if profile == nil { - log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") - break - } - log.Debug("New Peer Event: %v", e) + if eh.app != nil { + switch e.EventType { + case event.ACNStatus: + if e.Data[event.Progress] == "100" { + for _, onion := range eh.app.ListProfiles() { + // launch a listen thread (internally this does a check that the protocol engine is not listening) + // and as such is safe to call. + eh.app.GetPeer(onion).Listen() + } + } + case event.NewPeer: + onion := e.Data[event.Identity] + profile := eh.app.GetPeer(e.Data[event.Identity]) + if profile == nil { + log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") + break + } + log.Debug("New Peer Event: %v", e) - if e.Data["Reload"] != event.True { - eh.startHandlingPeer(onion) - } + if e.Data["Reload"] != event.True { + eh.startHandlingPeer(onion) + } - // CwtchPeer will always set this now... - tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) - e.Data[constants.Tag] = tag + // CwtchPeer will always set this now... + tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) + e.Data[constants.Tag] = tag - if e.Data[event.Created] == event.True { - profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) - } + if e.Data[event.Created] == event.True { + profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) + } - profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) - eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) - eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) + profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) + eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) + eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) - // If the user has chosen to block unknown profiles - // then explicitly configure the protocol engine to do so.. - settings := ReadGlobalSettings() - if settings.BlockUnknownConnections { - profile.BlockUnknownConnections() - } else { - // For completeness - profile.AllowUnknownConnections() - } + // If the user has chosen to block unknown profiles + // then explicitly configure the protocol engine to do so.. + settings := ReadGlobalSettings() + if settings.BlockUnknownConnections { + profile.BlockUnknownConnections() + } else { + // For completeness + profile.AllowUnknownConnections() + } - // Start up the Profile - profile.Listen() - profile.StartPeersConnections() - if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { - profile.StartServerConnections() - } + // Start up the Profile + profile.Listen() + profile.StartPeersConnections() + if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { + profile.StartServerConnections() + } - online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) - // Name always exists - e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) - // if a custom profile image exists then default to it. - key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - if !exists { - e.Data[constants2.Picture] = RandomProfileImage(onion) - } else { - e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) - serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) - profile.ShareFile(key, serializedManifest) - log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) - } + online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) + // Name always exists + e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) + // if a custom profile image exists then default to it. + key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + if !exists { + e.Data[constants2.Picture] = RandomProfileImage(onion) + } else { + e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) + serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) + profile.ShareFile(key, serializedManifest) + log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) + } - // Resolve the profile image of the profile. + // Resolve the profile image of the profile. - e.Data["Online"] = online + e.Data["Online"] = online - // If file sharing is enabled then reshare all active files... - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - if err == nil { - fsf.ReShareFiles(profile) - } + // If file sharing is enabled then reshare all active files... + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + if err == nil { + fsf.ReShareFiles(profile) + } - // Construct our conversations and our srever lists - var contacts []Contact - var servers []groups.Server + // Construct our conversations and our srever lists + var contacts []Contact + var servers []groups.Server - conversations, err := profile.FetchConversations() + conversations, err := profile.FetchConversations() - if err == nil { - // We have conversations attached to this profile... - for _, conversationInfo := range conversations { - // Only compile the server info if we have enabled the experiment... - // Note that this means that this info can become stale if when first loaded the experiment - // has been disabled and then is later re-enabled. As such we need to ensure that this list is - // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... - if conversationInfo.IsServer() { - groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) - if err == nil { - servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) - } - continue - } + if err == nil { + // We have conversations attached to this profile... + for _, conversationInfo := range conversations { + // Only compile the server info if we have enabled the experiment... + // Note that this means that this info can become stale if when first loaded the experiment + // has been disabled and then is later re-enabled. As such we need to ensure that this list is + // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... + if conversationInfo.IsServer() { + groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) + if err == nil { + servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) + } + continue + } - // Prefer local override to public name... - name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - name = conversationInfo.Handle - } - } + // Prefer local override to public name... + name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + name = conversationInfo.Handle + } + } - // Resolve the profile image of the contact - var cpicPath string - var defaultPath string - if conversationInfo.IsGroup() { - cpicPath = RandomGroupImage(conversationInfo.Handle) - defaultPath = RandomGroupImage(conversationInfo.Handle) - } else { - cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) - defaultPath = RandomProfileImage(conversationInfo.Handle) - } + // Resolve the profile image of the contact + var cpicPath string + var defaultPath string + if conversationInfo.IsGroup() { + cpicPath = RandomGroupImage(conversationInfo.Handle) + defaultPath = RandomGroupImage(conversationInfo.Handle) + } else { + cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) + defaultPath = RandomProfileImage(conversationInfo.Handle) + } - // Resolve Save History Setting - saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) - if !set { - saveHistory = event.DeleteHistoryDefault - } + // Resolve Save History Setting + saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) + if !set { + saveHistory = event.DeleteHistoryDefault + } - // Resolve Archived Setting - isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) - if !set { - isArchived = event.False - } + // Resolve Archived Setting + isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) + if !set { + isArchived = event.False + } - unread := 0 - lastSeenMessageId := -1 - lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) - if set { - lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) - if err == nil { - // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) - messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) - if err == nil { - for _, message := range messages { - msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) - if err == nil { - if msgTime.UTC().After(lastSeenTime.UTC()) { - unread++ - } else { - lastSeenMessageId = message.ID - break - } - } - } - } - } - } + unread := 0 + lastSeenMessageId := -1 + lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) + if set { + lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) + if err == nil { + // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) + messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) + if err == nil { + for _, message := range messages { + msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) + if err == nil { + if msgTime.UTC().After(lastSeenTime.UTC()) { + unread++ + } else { + lastSeenMessageId = message.ID + break + } + } + } + } + } + } - groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) + groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) - stateHandle := conversationInfo.Handle - if conversationInfo.IsGroup() { - stateHandle = groupServer - } - state := profile.GetPeerState(stateHandle) - if !set { - state = connections.DISCONNECTED - } + stateHandle := conversationInfo.Handle + if conversationInfo.IsGroup() { + stateHandle = groupServer + } + state := profile.GetPeerState(stateHandle) + if !set { + state = connections.DISCONNECTED + } - blocked := false - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = true - } + blocked := false + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = true + } - // Fetch the message count, and the time of the most recent message - count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) - } + // Fetch the message count, and the time of the most recent message + count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) + } - lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) + lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) - notificationPolicy := constants2.ConversationNotificationPolicyDefault - if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { - notificationPolicy = notificationPolicyAttr - } + notificationPolicy := constants2.ConversationNotificationPolicyDefault + if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { + notificationPolicy = notificationPolicyAttr + } - contacts = append(contacts, Contact{ - Name: name, - Identifier: conversationInfo.ID, - Onion: conversationInfo.Handle, - Status: connections.ConnectionStateName[state], - Picture: cpicPath, - DefaultPicture: defaultPath, - Accepted: conversationInfo.Accepted, - AccessControlList: conversationInfo.ACL, - Blocked: blocked, - SaveHistory: saveHistory, - Messages: count, - Unread: unread, - LastSeenMessageId: lastSeenMessageId, - LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), - IsGroup: conversationInfo.IsGroup(), - GroupServer: groupServer, - IsArchived: isArchived == event.True, - NotificationPolicy: notificationPolicy, - Attributes: conversationInfo.Attributes, - }) - } - } + contacts = append(contacts, Contact{ + Name: name, + Identifier: conversationInfo.ID, + Onion: conversationInfo.Handle, + Status: connections.ConnectionStateName[state], + Picture: cpicPath, + DefaultPicture: defaultPath, + Accepted: conversationInfo.Accepted, + AccessControlList: conversationInfo.ACL, + Blocked: blocked, + SaveHistory: saveHistory, + Messages: count, + Unread: unread, + LastSeenMessageId: lastSeenMessageId, + LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), + IsGroup: conversationInfo.IsGroup(), + GroupServer: groupServer, + IsArchived: isArchived == event.True, + NotificationPolicy: notificationPolicy, + Attributes: conversationInfo.Attributes, + }) + } + } - bytes, _ := json.Marshal(contacts) - e.Data["ContactsJson"] = string(bytes) + bytes, _ := json.Marshal(contacts) + e.Data["ContactsJson"] = string(bytes) - // Marshal the server list into the new peer event... - serversListBytes, _ := json.Marshal(servers) - e.Data[groups.ServerList] = string(serversListBytes) + // Marshal the server list into the new peer event... + serversListBytes, _ := json.Marshal(servers) + e.Data[groups.ServerList] = string(serversListBytes) - log.Debugf("contactsJson %v", e.Data["ContactsJson"]) - } - } + log.Debugf("contactsJson %v", e.Data["ContactsJson"]) + } + } - json, _ := json.Marshal(e) - return string(json) + json, _ := json.Marshal(e) + return string(json) } func GetProfileImage(profile peer.CwtchPeer, conversationInfo *model.Conversation, basepath string) string { - fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) - if err == nil { - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) - // check if the file exists...if it does then set the path... - if _, err := os.Stat(fp); err == nil { - image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) - return image - } - } - } - return RandomProfileImage(conversationInfo.Handle) + fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) + if err == nil { + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) + // check if the file exists...if it does then set the path... + if _, err := os.Stat(fp); err == nil { + image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) + return image + } + } + } + return RandomProfileImage(conversationInfo.Handle) } // handleProfileEvent enriches Profile events so they are usable with out further data fetches func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { - // cache of contact states to use to filter out events repeating known states - var contactStateCache = make(map[string]connections.ConnectionState) + // cache of contact states to use to filter out events repeating known states + var contactStateCache = make(map[string]connections.ConnectionState) - if eh.app == nil { - log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") - } else { - profile := eh.app.GetPeer(ev.Profile) - log.Debugf("New Profile Event to Handle: %v", ev) - switch ev.Event.EventType { - case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } else { - // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... - log.Errorf("todo wait for contact to be added before processing this event...") - return "" - } - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } + if eh.app == nil { + log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") + } else { + profile := eh.app.GetPeer(ev.Profile) + log.Debugf("New Profile Event to Handle: %v", ev) + switch ev.Event.EventType { + case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } else { + // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... + log.Errorf("todo wait for contact to be added before processing this event...") + return "" + } + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } - if ci.Accepted { - handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) - } + if ci.Accepted { + handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) + } - ev.Event.Data["notification"] = string(determineNotification(ci)) - case event.NewMessageFromGroup: - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - } - } - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } + ev.Event.Data["notification"] = string(determineNotification(ci)) + case event.NewMessageFromGroup: + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + } + } + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - if ci != nil && ci.Accepted { - handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) - } + if ci != nil && ci.Accepted { + handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) + } - gci, _ := profile.GetConversationInfo(conversationID) - groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] - state := profile.GetPeerState(groupServer) - // if syncing, don't flood with notifications - if state == connections.SYNCED { - ev.Event.Data["notification"] = string(determineNotification(gci)) - } else { - ev.Event.Data["notification"] = string(constants2.NotificationNone) - } - case event.PeerAcknowledgement: - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - } - case event.ContactCreated: - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - count, err := profile.GetChannelMessageCount(conversationID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationID, err) - } + gci, _ := profile.GetConversationInfo(conversationID) + groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] + state := profile.GetPeerState(groupServer) + // if syncing, don't flood with notifications + if state == connections.SYNCED { + ev.Event.Data["notification"] = string(determineNotification(gci)) + } else { + ev.Event.Data["notification"] = string(constants2.NotificationNone) + } + case event.PeerAcknowledgement: + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + } + case event.ContactCreated: + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + count, err := profile.GetChannelMessageCount(conversationID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationID, err) + } - conversationInfo, err := profile.GetConversationInfo(conversationID) - if err != nil { - log.Errorf("error fetching conversation info for %v %v", conversationID, err) - } + conversationInfo, err := profile.GetConversationInfo(conversationID) + if err != nil { + log.Errorf("error fetching conversation info for %v %v", conversationID, err) + } - blocked := constants.False - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = constants.True - } + blocked := constants.False + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = constants.True + } - accepted := constants.False - if conversationInfo.Accepted { - accepted = constants.True - } + accepted := constants.False + if conversationInfo.Accepted { + accepted = constants.True + } - acl, _ := json.Marshal(conversationInfo.ACL) + acl, _ := json.Marshal(conversationInfo.ACL) - lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) - ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... - ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data["numMessages"] = strconv.Itoa(count) - ev.Event.Data["nick"] = conversationInfo.Handle - ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] - ev.Event.Data["accepted"] = accepted - ev.Event.Data["accessControlList"] = string(acl) - ev.Event.Data["blocked"] = blocked - ev.Event.Data["loading"] = "false" - ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) - case event.GroupCreated: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) - ev.Event.Data[constants2.Picture] = groupPic + lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) + ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... + ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data["numMessages"] = strconv.Itoa(count) + ev.Event.Data["nick"] = conversationInfo.Handle + ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] + ev.Event.Data["accepted"] = accepted + ev.Event.Data["accessControlList"] = string(acl) + ev.Event.Data["blocked"] = blocked + ev.Event.Data["loading"] = "false" + ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) + case event.GroupCreated: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - case event.NewGroup: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - serializedInvite := ev.Event.Data[event.GroupInvite] - if invite, err := model.ValidateInvite(serializedInvite); err == nil { - groupPic := RandomGroupImage(invite.GroupID) - ev.Event.Data[constants2.Picture] = groupPic + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + case event.NewGroup: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + serializedInvite := ev.Event.Data[event.GroupInvite] + if invite, err := model.ValidateInvite(serializedInvite); err == nil { + groupPic := RandomGroupImage(invite.GroupID) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - } else { - log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) - return "" - } - case event.PeerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + } else { + log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) + return "" + } + case event.PeerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) + contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) - if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { - return "" // suppress events from our own profile... - } + if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { + return "" // suppress events from our own profile... + } - // We do not know who this is...don't send any event until we see a message from them - // (at that point the conversation will have been created...) - if contact == nil || err != nil || contact.ID == 0 { - return "" - } + // We do not know who this is...don't send any event until we see a message from them + // (at that point the conversation will have been created...) + if contact == nil || err != nil || contact.ID == 0 { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - if contact != nil { - // No enrichment needed - if cxnState == connections.AUTHENTICATED { - // if known and authed, get vars - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } - case event.ServerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + if contact != nil { + // No enrichment needed + if cxnState == connections.AUTHENTICATED { + // if known and authed, get vars + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } + case event.ServerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - case event.NewRetValMessageFromPeer: - // auto handled event means the setting is already done, we're just deciding if we need to tell the UI - onion := ev.Event.Data[event.RemotePeer] - scope := ev.Event.Data[event.Scope] - path := ev.Event.Data[event.Path] - val := ev.Event.Data[event.Data] - exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) + case event.NewRetValMessageFromPeer: + // auto handled event means the setting is already done, we're just deciding if we need to tell the UI + onion := ev.Event.Data[event.RemotePeer] + scope := ev.Event.Data[event.Scope] + path := ev.Event.Data[event.Path] + val := ev.Event.Data[event.Data] + exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) - conversation, err := profile.FetchConversationInfo(onion) - if err == nil { + conversation, err := profile.FetchConversationInfo(onion) + if err == nil { - if exists && attr.IntoScope(scope) == attr.PublicScope { - zone, path := attr.ParseZone(path) + if exists && attr.IntoScope(scope) == attr.PublicScope { + zone, path := attr.ParseZone(path) - // auto download profile images from contacts... - settings := ReadGlobalSettings() - if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { - fileKey := val - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled && conversation.Accepted { + // auto download profile images from contacts... + settings := ReadGlobalSettings() + if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { + fileKey := val + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if err == nil && imagePreviewsEnabled && conversation.Accepted { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - if _, err := os.Stat(fp); err == nil { - // file is marked as completed downloaded and exists... - return "" - } else { - // the user probably deleted the file, mark completed as false... - profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) - } - } + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + if _, err := os.Stat(fp); err == nil { + // file is marked as completed downloaded and exists... + return "" + } else { + // the user probably deleted the file, mark completed as false... + profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) + } + } - log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) - ev.Event.Data[event.FilePath] = fp - fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) - } else { - // if image previews are disabled then ignore this event... - return "" - } - } - if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { - // we have a locally set override, don't pass this remote set public scope update to UI - return "" - } - } - } - } - } + log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) + ev.Event.Data[event.FilePath] = fp + fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) + } else { + // if image previews are disabled then ignore this event... + return "" + } + } + if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { + // we have a locally set override, don't pass this remote set public scope update to UI + return "" + } + } + } + } + } - json, _ := json.Marshal(unwrap(ev)) - return string(json) + json, _ := json.Marshal(unwrap(ev)) + return string(json) } func unwrap(original *EventProfileEnvelope) *event.Event { - unwrapped := &original.Event - unwrapped.Data["ProfileOnion"] = original.Profile - return unwrapped + unwrapped := &original.Event + unwrapped.Data["ProfileOnion"] = original.Profile + return unwrapped } func (eh *EventHandler) startHandlingPeer(onion string) { - eventBus := eh.app.GetEventBus(onion) - q := event.NewQueue() + eventBus := eh.app.GetEventBus(onion) + q := event.NewQueue() - eventBus.Subscribe(event.NetworkStatus, q) - eventBus.Subscribe(event.ACNInfo, q) - eventBus.Subscribe(event.NewMessageFromPeer, q) - eventBus.Subscribe(event.UpdatedProfileAttribute, q) - eventBus.Subscribe(event.PeerAcknowledgement, q) - eventBus.Subscribe(event.DeleteContact, q) - eventBus.Subscribe(event.AppError, q) - eventBus.Subscribe(event.IndexedAcknowledgement, q) - eventBus.Subscribe(event.IndexedFailure, q) - eventBus.Subscribe(event.ContactCreated, q) - eventBus.Subscribe(event.NewMessageFromGroup, q) - eventBus.Subscribe(event.GroupCreated, q) - eventBus.Subscribe(event.NewGroup, q) - eventBus.Subscribe(event.ServerStateChange, q) - eventBus.Subscribe(event.PeerStateChange, q) - eventBus.Subscribe(event.NewRetValMessageFromPeer, q) - eventBus.Subscribe(event.ShareManifest, q) - eventBus.Subscribe(event.ManifestSizeReceived, q) - eventBus.Subscribe(event.ManifestError, q) - eventBus.Subscribe(event.ManifestReceived, q) - eventBus.Subscribe(event.ManifestSaved, q) - eventBus.Subscribe(event.FileDownloadProgressUpdate, q) - eventBus.Subscribe(event.FileDownloaded, q) + eventBus.Subscribe(event.NetworkStatus, q) + eventBus.Subscribe(event.ACNInfo, q) + eventBus.Subscribe(event.NewMessageFromPeer, q) + eventBus.Subscribe(event.UpdatedProfileAttribute, q) + eventBus.Subscribe(event.PeerAcknowledgement, q) + eventBus.Subscribe(event.DeleteContact, q) + eventBus.Subscribe(event.AppError, q) + eventBus.Subscribe(event.IndexedAcknowledgement, q) + eventBus.Subscribe(event.IndexedFailure, q) + eventBus.Subscribe(event.ContactCreated, q) + eventBus.Subscribe(event.NewMessageFromGroup, q) + eventBus.Subscribe(event.GroupCreated, q) + eventBus.Subscribe(event.NewGroup, q) + eventBus.Subscribe(event.ServerStateChange, q) + eventBus.Subscribe(event.PeerStateChange, q) + eventBus.Subscribe(event.NewRetValMessageFromPeer, q) + eventBus.Subscribe(event.ShareManifest, q) + eventBus.Subscribe(event.ManifestSizeReceived, q) + eventBus.Subscribe(event.ManifestError, q) + eventBus.Subscribe(event.ManifestReceived, q) + eventBus.Subscribe(event.ManifestSaved, q) + eventBus.Subscribe(event.FileDownloadProgressUpdate, q) + eventBus.Subscribe(event.FileDownloaded, q) - go eh.forwardProfileMessages(onion, q) + go eh.forwardProfileMessages(onion, q) } func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) { - log.Infof("Launching Forwarding Goroutine") - // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine - for { - e := q.Next() - ev := EventProfileEnvelope{Event: e, Profile: onion} - eh.profileEvents <- ev - if ev.Event.EventType == event.Shutdown { - return - } - } + log.Infof("Launching Forwarding Goroutine") + // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine + for { + e := q.Next() + ev := EventProfileEnvelope{Event: e, Profile: onion} + eh.profileEvents <- ev + if ev.Event.EventType == event.Shutdown { + return + } + } } // Push pushes an event onto the app event bus // It is also a way for libCwtch-go to publish an event for consumption by a UI before a Cwtch app has been initialized // use: to signal an error before a cwtch app could be created func (eh *EventHandler) Push(newEvent event.Event) { - eh.appBusQueue.Publish(newEvent) + eh.appBusQueue.Publish(newEvent) } func getLastMessageTime(conversationMessages []model.ConversationMessage) int { - if len(conversationMessages) == 0 { - return 0 - } - time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) - if err != nil { - return 0 - } - return int(time.Unix()) + if len(conversationMessages) == 0 { + return 0 + } + time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) + if err != nil { + return 0 + } + return int(time.Unix()) } // handleImagePreviews checks settings and, if appropriate, auto-downloads any images func handleImagePreviews(profile peer.CwtchPeer, ev *event.Event, conversationID, senderID int) { - settings := ReadGlobalSettings() - fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) + settings := ReadGlobalSettings() + fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) - // Short-circuit failures - // Don't autodownload images if the download path does not exist. - if settings.DownloadPath == "" { - return - } + // Short-circuit if file sharing is disabled + if err != nil { + return + } - // Don't autodownload images if the download path does not exist. - if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { - return - } + // Short-circuit failures + // Don't autodownload images if the download path does not exist. + if settings.DownloadPath == "" { + return + } - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled { - var cm model.MessageWrapper - err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) - if err == nil && cm.Overlay == model.OverlayFileSharing { - var fm filesharing.OverlayMessage - err = json.Unmarshal([]byte(cm.Data), &fm) - if err == nil { - if fm.ShouldAutoDL() { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) - log.Debugf("autodownloading file!") - ev.Data["Auto"] = constants.True - mID, _ := strconv.Atoi(ev.Data["Index"]) - profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) - fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) - } - } - } - } + // Don't autodownload images if the download path does not exist. + if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { + return + } + + // Now look at the image preview experiment + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if imagePreviewsEnabled { + var cm model.MessageWrapper + err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) + if err == nil && cm.Overlay == model.OverlayFileSharing { + var fm filesharing.OverlayMessage + err = json.Unmarshal([]byte(cm.Data), &fm) + if err == nil { + if fm.ShouldAutoDL() { + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) + log.Debugf("autodownloading file!") + ev.Data["Auto"] = constants.True + mID, _ := strconv.Atoi(ev.Data["Index"]) + profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) + fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) + } + } + } + } } From f66921b5ce2ec221ef584720172addae886da2ff Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 26 Aug 2022 10:58:18 -0700 Subject: [PATCH 4/4] Format --- utils/eventHandler.go | 1102 ++++++++++++++++++++--------------------- 1 file changed, 551 insertions(+), 551 deletions(-) diff --git a/utils/eventHandler.go b/utils/eventHandler.go index f9f5676..ad5f29e 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -1,675 +1,675 @@ package utils import ( - "encoding/json" - "fmt" - "os" - "strconv" + "encoding/json" + "fmt" + "os" + "strconv" - "cwtch.im/cwtch/app" - "cwtch.im/cwtch/app/plugins" - "cwtch.im/cwtch/model" - "cwtch.im/cwtch/model/attr" - "cwtch.im/cwtch/model/constants" - "cwtch.im/cwtch/peer" - "cwtch.im/cwtch/protocol/connections" - constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" - "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" - "git.openprivacy.ca/openprivacy/log" + "cwtch.im/cwtch/app" + "cwtch.im/cwtch/app/plugins" + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/model/constants" + "cwtch.im/cwtch/peer" + "cwtch.im/cwtch/protocol/connections" + constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" + "git.openprivacy.ca/openprivacy/log" - "time" + "time" - "cwtch.im/cwtch/event" - "cwtch.im/cwtch/functionality/filesharing" + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/functionality/filesharing" ) type EventProfileEnvelope struct { - Event event.Event - Profile string + Event event.Event + Profile string } type EventHandler struct { - app app.Application - appBusQueue event.Queue - profileEvents chan EventProfileEnvelope + app app.Application + appBusQueue event.Queue + profileEvents chan EventProfileEnvelope } // We should be reading from profile events pretty quickly, but we make this buffer fairly large... const profileEventsBufferSize = 512 func NewEventHandler() *EventHandler { - eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} - return eh + eh := &EventHandler{app: nil, appBusQueue: event.NewQueue(), profileEvents: make(chan EventProfileEnvelope, profileEventsBufferSize)} + return eh } func (eh *EventHandler) HandleApp(application app.Application) { - eh.app = application - application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) + eh.app = application + application.GetPrimaryBus().Subscribe(event.NewPeer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.PeerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.Shutdown, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(UpdateGlobalSettings, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(CwtchStarted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(servers.ServerStatsUpdate, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.StartingStorageMiragtion, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(event.DoneStorageMigration, eh.appBusQueue) } func (eh *EventHandler) GetNextEvent() string { - appChan := eh.appBusQueue.OutChan() + appChan := eh.appBusQueue.OutChan() - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - default: - select { - case e := <-appChan: - return eh.handleAppBusEvent(&e) - case ev := <-eh.profileEvents: - return eh.handleProfileEvent(&ev) - } - } + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + default: + select { + case e := <-appChan: + return eh.handleAppBusEvent(&e) + case ev := <-eh.profileEvents: + return eh.handleProfileEvent(&ev) + } + } } // handleAppBusEvent enriches AppBus events so they are usable with out further data fetches func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { - if eh.app != nil { - switch e.EventType { - case event.ACNStatus: - if e.Data[event.Progress] == "100" { - for _, onion := range eh.app.ListProfiles() { - // launch a listen thread (internally this does a check that the protocol engine is not listening) - // and as such is safe to call. - eh.app.GetPeer(onion).Listen() - } - } - case event.NewPeer: - onion := e.Data[event.Identity] - profile := eh.app.GetPeer(e.Data[event.Identity]) - if profile == nil { - log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") - break - } - log.Debug("New Peer Event: %v", e) + if eh.app != nil { + switch e.EventType { + case event.ACNStatus: + if e.Data[event.Progress] == "100" { + for _, onion := range eh.app.ListProfiles() { + // launch a listen thread (internally this does a check that the protocol engine is not listening) + // and as such is safe to call. + eh.app.GetPeer(onion).Listen() + } + } + case event.NewPeer: + onion := e.Data[event.Identity] + profile := eh.app.GetPeer(e.Data[event.Identity]) + if profile == nil { + log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") + break + } + log.Debug("New Peer Event: %v", e) - if e.Data["Reload"] != event.True { - eh.startHandlingPeer(onion) - } + if e.Data["Reload"] != event.True { + eh.startHandlingPeer(onion) + } - // CwtchPeer will always set this now... - tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) - e.Data[constants.Tag] = tag + // CwtchPeer will always set this now... + tag, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.Tag) + e.Data[constants.Tag] = tag - if e.Data[event.Created] == event.True { - profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) - } + if e.Data[event.Created] == event.True { + profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.Picture, ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) + } - profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) - eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) - eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) + profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline, event.False) + eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY) + eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK) - // If the user has chosen to block unknown profiles - // then explicitly configure the protocol engine to do so.. - settings := ReadGlobalSettings() - if settings.BlockUnknownConnections { - profile.BlockUnknownConnections() - } else { - // For completeness - profile.AllowUnknownConnections() - } + // If the user has chosen to block unknown profiles + // then explicitly configure the protocol engine to do so.. + settings := ReadGlobalSettings() + if settings.BlockUnknownConnections { + profile.BlockUnknownConnections() + } else { + // For completeness + profile.AllowUnknownConnections() + } - // Start up the Profile - profile.Listen() - profile.StartPeersConnections() - if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { - profile.StartServerConnections() - } + // Start up the Profile + profile.Listen() + profile.StartPeersConnections() + if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil { + profile.StartServerConnections() + } - online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) - // Name always exists - e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) - // if a custom profile image exists then default to it. - key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - if !exists { - e.Data[constants2.Picture] = RandomProfileImage(onion) - } else { - e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) - serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) - profile.ShareFile(key, serializedManifest) - log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) - } + online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) + // Name always exists + e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) + // if a custom profile image exists then default to it. + key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + if !exists { + e.Data[constants2.Picture] = RandomProfileImage(onion) + } else { + e.Data[constants2.Picture], _ = profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", key)) + serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) + profile.ShareFile(key, serializedManifest) + log.Debugf("Custom Profile Image: %v %s", e.Data[constants2.Picture], serializedManifest) + } - // Resolve the profile image of the profile. + // Resolve the profile image of the profile. - e.Data["Online"] = online + e.Data["Online"] = online - // If file sharing is enabled then reshare all active files... - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - if err == nil { - fsf.ReShareFiles(profile) - } + // If file sharing is enabled then reshare all active files... + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + if err == nil { + fsf.ReShareFiles(profile) + } - // Construct our conversations and our srever lists - var contacts []Contact - var servers []groups.Server + // Construct our conversations and our srever lists + var contacts []Contact + var servers []groups.Server - conversations, err := profile.FetchConversations() + conversations, err := profile.FetchConversations() - if err == nil { - // We have conversations attached to this profile... - for _, conversationInfo := range conversations { - // Only compile the server info if we have enabled the experiment... - // Note that this means that this info can become stale if when first loaded the experiment - // has been disabled and then is later re-enabled. As such we need to ensure that this list is - // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... - if conversationInfo.IsServer() { - groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) - if err == nil { - servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) - } - continue - } + if err == nil { + // We have conversations attached to this profile... + for _, conversationInfo := range conversations { + // Only compile the server info if we have enabled the experiment... + // Note that this means that this info can become stale if when first loaded the experiment + // has been disabled and then is later re-enabled. As such we need to ensure that this list is + // re-fetched when the group experiment is enabled via a dedicated ListServerInfo event... + if conversationInfo.IsServer() { + groupHandler, err := groups.ExperimentGate(ReadGlobalSettings().Experiments) + if err == nil { + servers = append(servers, groupHandler.GetServerInfo(conversationInfo.Handle, profile)) + } + continue + } - // Prefer local override to public name... - name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - name = conversationInfo.Handle - } - } + // Prefer local override to public name... + name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + name = conversationInfo.Handle + } + } - // Resolve the profile image of the contact - var cpicPath string - var defaultPath string - if conversationInfo.IsGroup() { - cpicPath = RandomGroupImage(conversationInfo.Handle) - defaultPath = RandomGroupImage(conversationInfo.Handle) - } else { - cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) - defaultPath = RandomProfileImage(conversationInfo.Handle) - } + // Resolve the profile image of the contact + var cpicPath string + var defaultPath string + if conversationInfo.IsGroup() { + cpicPath = RandomGroupImage(conversationInfo.Handle) + defaultPath = RandomGroupImage(conversationInfo.Handle) + } else { + cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) + defaultPath = RandomProfileImage(conversationInfo.Handle) + } - // Resolve Save History Setting - saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) - if !set { - saveHistory = event.DeleteHistoryDefault - } + // Resolve Save History Setting + saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) + if !set { + saveHistory = event.DeleteHistoryDefault + } - // Resolve Archived Setting - isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) - if !set { - isArchived = event.False - } + // Resolve Archived Setting + isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) + if !set { + isArchived = event.False + } - unread := 0 - lastSeenMessageId := -1 - lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) - if set { - lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) - if err == nil { - // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) - messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) - if err == nil { - for _, message := range messages { - msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) - if err == nil { - if msgTime.UTC().After(lastSeenTime.UTC()) { - unread++ - } else { - lastSeenMessageId = message.ID - break - } - } - } - } - } - } + unread := 0 + lastSeenMessageId := -1 + lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime) + if set { + lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr) + if err == nil { + // get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after) + messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100) + if err == nil { + for _, message := range messages { + msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp]) + if err == nil { + if msgTime.UTC().After(lastSeenTime.UTC()) { + unread++ + } else { + lastSeenMessageId = message.ID + break + } + } + } + } + } + } - groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) + groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) - stateHandle := conversationInfo.Handle - if conversationInfo.IsGroup() { - stateHandle = groupServer - } - state := profile.GetPeerState(stateHandle) - if !set { - state = connections.DISCONNECTED - } + stateHandle := conversationInfo.Handle + if conversationInfo.IsGroup() { + stateHandle = groupServer + } + state := profile.GetPeerState(stateHandle) + if !set { + state = connections.DISCONNECTED + } - blocked := false - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = true - } + blocked := false + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = true + } - // Fetch the message count, and the time of the most recent message - count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) - } + // Fetch the message count, and the time of the most recent message + count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) + } - lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) + lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) - notificationPolicy := constants2.ConversationNotificationPolicyDefault - if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { - notificationPolicy = notificationPolicyAttr - } + notificationPolicy := constants2.ConversationNotificationPolicyDefault + if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists { + notificationPolicy = notificationPolicyAttr + } - contacts = append(contacts, Contact{ - Name: name, - Identifier: conversationInfo.ID, - Onion: conversationInfo.Handle, - Status: connections.ConnectionStateName[state], - Picture: cpicPath, - DefaultPicture: defaultPath, - Accepted: conversationInfo.Accepted, - AccessControlList: conversationInfo.ACL, - Blocked: blocked, - SaveHistory: saveHistory, - Messages: count, - Unread: unread, - LastSeenMessageId: lastSeenMessageId, - LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), - IsGroup: conversationInfo.IsGroup(), - GroupServer: groupServer, - IsArchived: isArchived == event.True, - NotificationPolicy: notificationPolicy, - Attributes: conversationInfo.Attributes, - }) - } - } + contacts = append(contacts, Contact{ + Name: name, + Identifier: conversationInfo.ID, + Onion: conversationInfo.Handle, + Status: connections.ConnectionStateName[state], + Picture: cpicPath, + DefaultPicture: defaultPath, + Accepted: conversationInfo.Accepted, + AccessControlList: conversationInfo.ACL, + Blocked: blocked, + SaveHistory: saveHistory, + Messages: count, + Unread: unread, + LastSeenMessageId: lastSeenMessageId, + LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), + IsGroup: conversationInfo.IsGroup(), + GroupServer: groupServer, + IsArchived: isArchived == event.True, + NotificationPolicy: notificationPolicy, + Attributes: conversationInfo.Attributes, + }) + } + } - bytes, _ := json.Marshal(contacts) - e.Data["ContactsJson"] = string(bytes) + bytes, _ := json.Marshal(contacts) + e.Data["ContactsJson"] = string(bytes) - // Marshal the server list into the new peer event... - serversListBytes, _ := json.Marshal(servers) - e.Data[groups.ServerList] = string(serversListBytes) + // Marshal the server list into the new peer event... + serversListBytes, _ := json.Marshal(servers) + e.Data[groups.ServerList] = string(serversListBytes) - log.Debugf("contactsJson %v", e.Data["ContactsJson"]) - } - } + log.Debugf("contactsJson %v", e.Data["ContactsJson"]) + } + } - json, _ := json.Marshal(e) - return string(json) + json, _ := json.Marshal(e) + return string(json) } func GetProfileImage(profile peer.CwtchPeer, conversationInfo *model.Conversation, basepath string) string { - fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) - if err == nil { - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) - // check if the file exists...if it does then set the path... - if _, err := os.Stat(fp); err == nil { - image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) - return image - } - } - } - return RandomProfileImage(conversationInfo.Handle) + fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) + if err == nil { + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) + // check if the file exists...if it does then set the path... + if _, err := os.Stat(fp); err == nil { + image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) + return image + } + } + } + return RandomProfileImage(conversationInfo.Handle) } // handleProfileEvent enriches Profile events so they are usable with out further data fetches func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { - // cache of contact states to use to filter out events repeating known states - var contactStateCache = make(map[string]connections.ConnectionState) + // cache of contact states to use to filter out events repeating known states + var contactStateCache = make(map[string]connections.ConnectionState) - if eh.app == nil { - log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") - } else { - profile := eh.app.GetPeer(ev.Profile) - log.Debugf("New Profile Event to Handle: %v", ev) - switch ev.Event.EventType { - case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } else { - // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... - log.Errorf("todo wait for contact to be added before processing this event...") - return "" - } - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } + if eh.app == nil { + log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?") + } else { + profile := eh.app.GetPeer(ev.Profile) + log.Debugf("New Profile Event to Handle: %v", ev) + switch ev.Event.EventType { + case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } else { + // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... + log.Errorf("todo wait for contact to be added before processing this event...") + return "" + } + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + // If we dont have a name val for a peer, but they have sent us a message, we might be approved now, re-ask + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(ci.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } - if ci.Accepted { - handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) - } + if ci.Accepted { + handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) + } - ev.Event.Data["notification"] = string(determineNotification(ci)) - case event.NewMessageFromGroup: - // only needs contact nickname and picture, for displaying on popup notifications - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - var exists bool - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - if !exists { - ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] - } - } - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) - } + ev.Event.Data["notification"] = string(determineNotification(ci)) + case event.NewMessageFromGroup: + // only needs contact nickname and picture, for displaying on popup notifications + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + ev.Event.Data[constants2.Picture] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + var exists bool + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) + if !exists { + ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] + } + } + ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath) + } - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - if ci != nil && ci.Accepted { - handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) - } + if ci != nil && ci.Accepted { + handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) + } - gci, _ := profile.GetConversationInfo(conversationID) - groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] - state := profile.GetPeerState(groupServer) - // if syncing, don't flood with notifications - if state == connections.SYNCED { - ev.Event.Data["notification"] = string(determineNotification(gci)) - } else { - ev.Event.Data["notification"] = string(constants2.NotificationNone) - } - case event.PeerAcknowledgement: - ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) - if ci != nil && err == nil { - ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) - } - case event.ContactCreated: - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - count, err := profile.GetChannelMessageCount(conversationID, 0) - if err != nil { - log.Errorf("error fetching channel message count %v %v", conversationID, err) - } + gci, _ := profile.GetConversationInfo(conversationID) + groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] + state := profile.GetPeerState(groupServer) + // if syncing, don't flood with notifications + if state == connections.SYNCED { + ev.Event.Data["notification"] = string(determineNotification(gci)) + } else { + ev.Event.Data["notification"] = string(constants2.NotificationNone) + } + case event.PeerAcknowledgement: + ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) + if ci != nil && err == nil { + ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) + } + case event.ContactCreated: + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + count, err := profile.GetChannelMessageCount(conversationID, 0) + if err != nil { + log.Errorf("error fetching channel message count %v %v", conversationID, err) + } - conversationInfo, err := profile.GetConversationInfo(conversationID) - if err != nil { - log.Errorf("error fetching conversation info for %v %v", conversationID, err) - } + conversationInfo, err := profile.GetConversationInfo(conversationID) + if err != nil { + log.Errorf("error fetching conversation info for %v %v", conversationID, err) + } - blocked := constants.False - if conversationInfo.ACL[conversationInfo.Handle].Blocked { - blocked = constants.True - } + blocked := constants.False + if conversationInfo.ACL[conversationInfo.Handle].Blocked { + blocked = constants.True + } - accepted := constants.False - if conversationInfo.Accepted { - accepted = constants.True - } + accepted := constants.False + if conversationInfo.Accepted { + accepted = constants.True + } - acl, _ := json.Marshal(conversationInfo.ACL) + acl, _ := json.Marshal(conversationInfo.ACL) - lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) - ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... - ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) - ev.Event.Data["numMessages"] = strconv.Itoa(count) - ev.Event.Data["nick"] = conversationInfo.Handle - ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] - ev.Event.Data["accepted"] = accepted - ev.Event.Data["accessControlList"] = string(acl) - ev.Event.Data["blocked"] = blocked - ev.Event.Data["loading"] = "false" - ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) - case event.GroupCreated: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) - ev.Event.Data[constants2.Picture] = groupPic + lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) + ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... + ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data["numMessages"] = strconv.Itoa(count) + ev.Event.Data["nick"] = conversationInfo.Handle + ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] + ev.Event.Data["accepted"] = accepted + ev.Event.Data["accessControlList"] = string(acl) + ev.Event.Data["blocked"] = blocked + ev.Event.Data["loading"] = "false" + ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) + case event.GroupCreated: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + groupPic := RandomGroupImage(ev.Event.Data[event.GroupID]) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - case event.NewGroup: - // This event should only happen after we have validated the invite, as such the error - // condition *should* never happen. - serializedInvite := ev.Event.Data[event.GroupInvite] - if invite, err := model.ValidateInvite(serializedInvite); err == nil { - groupPic := RandomGroupImage(invite.GroupID) - ev.Event.Data[constants2.Picture] = groupPic + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + case event.NewGroup: + // This event should only happen after we have validated the invite, as such the error + // condition *should* never happen. + serializedInvite := ev.Event.Data[event.GroupInvite] + if invite, err := model.ValidateInvite(serializedInvite); err == nil { + groupPic := RandomGroupImage(invite.GroupID) + ev.Event.Data[constants2.Picture] = groupPic - conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - conversationInfo, _ := profile.GetConversationInfo(conversationID) - acl, _ := json.Marshal(conversationInfo.ACL) - ev.Event.Data["accessControlList"] = string(acl) - } else { - log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) - return "" - } - case event.PeerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) + conversationInfo, _ := profile.GetConversationInfo(conversationID) + acl, _ := json.Marshal(conversationInfo.ACL) + ev.Event.Data["accessControlList"] = string(acl) + } else { + log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err) + return "" + } + case event.PeerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) + contact, err := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer]) - if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { - return "" // suppress events from our own profile... - } + if ev.Event.Data[event.RemotePeer] == profile.GetOnion() { + return "" // suppress events from our own profile... + } - // We do not know who this is...don't send any event until we see a message from them - // (at that point the conversation will have been created...) - if contact == nil || err != nil || contact.ID == 0 { - return "" - } + // We do not know who this is...don't send any event until we see a message from them + // (at that point the conversation will have been created...) + if contact == nil || err != nil || contact.ID == 0 { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - if contact != nil { - // No enrichment needed - if cxnState == connections.AUTHENTICATED { - // if known and authed, get vars - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) - profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - } - } - case event.ServerStateChange: - cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] + if contact != nil { + // No enrichment needed + if cxnState == connections.AUTHENTICATED { + // if known and authed, get vars + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.Name) + profile.SendScopedZonedGetValToContact(contact.ID, attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) + } + } + case event.ServerStateChange: + cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] - // skip events the UI doesn't act on - if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { - return "" - } + // skip events the UI doesn't act on + if cxnState == connections.CONNECTING || cxnState == connections.CONNECTED { + return "" + } - // if we already know this state, suppress - if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { - return "" - } - contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState + // if we already know this state, suppress + if knownState, exists := contactStateCache[ev.Event.Data[event.RemotePeer]]; exists && cxnState == knownState { + return "" + } + contactStateCache[ev.Event.Data[event.RemotePeer]] = cxnState - case event.NewRetValMessageFromPeer: - // auto handled event means the setting is already done, we're just deciding if we need to tell the UI - onion := ev.Event.Data[event.RemotePeer] - scope := ev.Event.Data[event.Scope] - path := ev.Event.Data[event.Path] - val := ev.Event.Data[event.Data] - exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) + case event.NewRetValMessageFromPeer: + // auto handled event means the setting is already done, we're just deciding if we need to tell the UI + onion := ev.Event.Data[event.RemotePeer] + scope := ev.Event.Data[event.Scope] + path := ev.Event.Data[event.Path] + val := ev.Event.Data[event.Data] + exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) - conversation, err := profile.FetchConversationInfo(onion) - if err == nil { + conversation, err := profile.FetchConversationInfo(onion) + if err == nil { - if exists && attr.IntoScope(scope) == attr.PublicScope { - zone, path := attr.ParseZone(path) + if exists && attr.IntoScope(scope) == attr.PublicScope { + zone, path := attr.ParseZone(path) - // auto download profile images from contacts... - settings := ReadGlobalSettings() - if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { - fileKey := val - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled && conversation.Accepted { + // auto download profile images from contacts... + settings := ReadGlobalSettings() + if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { + fileKey := val + fsf, err := filesharing.FunctionalityGate(settings.Experiments) + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if err == nil && imagePreviewsEnabled && conversation.Accepted { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - if _, err := os.Stat(fp); err == nil { - // file is marked as completed downloaded and exists... - return "" - } else { - // the user probably deleted the file, mark completed as false... - profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) - } - } + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + if _, err := os.Stat(fp); err == nil { + // file is marked as completed downloaded and exists... + return "" + } else { + // the user probably deleted the file, mark completed as false... + profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) + } + } - log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) - ev.Event.Data[event.FilePath] = fp - fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) - } else { - // if image previews are disabled then ignore this event... - return "" - } - } - if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { - // we have a locally set override, don't pass this remote set public scope update to UI - return "" - } - } - } - } - } + log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) + ev.Event.Data[event.FilePath] = fp + fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) + } else { + // if image previews are disabled then ignore this event... + return "" + } + } + if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { + // we have a locally set override, don't pass this remote set public scope update to UI + return "" + } + } + } + } + } - json, _ := json.Marshal(unwrap(ev)) - return string(json) + json, _ := json.Marshal(unwrap(ev)) + return string(json) } func unwrap(original *EventProfileEnvelope) *event.Event { - unwrapped := &original.Event - unwrapped.Data["ProfileOnion"] = original.Profile - return unwrapped + unwrapped := &original.Event + unwrapped.Data["ProfileOnion"] = original.Profile + return unwrapped } func (eh *EventHandler) startHandlingPeer(onion string) { - eventBus := eh.app.GetEventBus(onion) - q := event.NewQueue() + eventBus := eh.app.GetEventBus(onion) + q := event.NewQueue() - eventBus.Subscribe(event.NetworkStatus, q) - eventBus.Subscribe(event.ACNInfo, q) - eventBus.Subscribe(event.NewMessageFromPeer, q) - eventBus.Subscribe(event.UpdatedProfileAttribute, q) - eventBus.Subscribe(event.PeerAcknowledgement, q) - eventBus.Subscribe(event.DeleteContact, q) - eventBus.Subscribe(event.AppError, q) - eventBus.Subscribe(event.IndexedAcknowledgement, q) - eventBus.Subscribe(event.IndexedFailure, q) - eventBus.Subscribe(event.ContactCreated, q) - eventBus.Subscribe(event.NewMessageFromGroup, q) - eventBus.Subscribe(event.GroupCreated, q) - eventBus.Subscribe(event.NewGroup, q) - eventBus.Subscribe(event.ServerStateChange, q) - eventBus.Subscribe(event.PeerStateChange, q) - eventBus.Subscribe(event.NewRetValMessageFromPeer, q) - eventBus.Subscribe(event.ShareManifest, q) - eventBus.Subscribe(event.ManifestSizeReceived, q) - eventBus.Subscribe(event.ManifestError, q) - eventBus.Subscribe(event.ManifestReceived, q) - eventBus.Subscribe(event.ManifestSaved, q) - eventBus.Subscribe(event.FileDownloadProgressUpdate, q) - eventBus.Subscribe(event.FileDownloaded, q) + eventBus.Subscribe(event.NetworkStatus, q) + eventBus.Subscribe(event.ACNInfo, q) + eventBus.Subscribe(event.NewMessageFromPeer, q) + eventBus.Subscribe(event.UpdatedProfileAttribute, q) + eventBus.Subscribe(event.PeerAcknowledgement, q) + eventBus.Subscribe(event.DeleteContact, q) + eventBus.Subscribe(event.AppError, q) + eventBus.Subscribe(event.IndexedAcknowledgement, q) + eventBus.Subscribe(event.IndexedFailure, q) + eventBus.Subscribe(event.ContactCreated, q) + eventBus.Subscribe(event.NewMessageFromGroup, q) + eventBus.Subscribe(event.GroupCreated, q) + eventBus.Subscribe(event.NewGroup, q) + eventBus.Subscribe(event.ServerStateChange, q) + eventBus.Subscribe(event.PeerStateChange, q) + eventBus.Subscribe(event.NewRetValMessageFromPeer, q) + eventBus.Subscribe(event.ShareManifest, q) + eventBus.Subscribe(event.ManifestSizeReceived, q) + eventBus.Subscribe(event.ManifestError, q) + eventBus.Subscribe(event.ManifestReceived, q) + eventBus.Subscribe(event.ManifestSaved, q) + eventBus.Subscribe(event.FileDownloadProgressUpdate, q) + eventBus.Subscribe(event.FileDownloaded, q) - go eh.forwardProfileMessages(onion, q) + go eh.forwardProfileMessages(onion, q) } func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) { - log.Infof("Launching Forwarding Goroutine") - // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine - for { - e := q.Next() - ev := EventProfileEnvelope{Event: e, Profile: onion} - eh.profileEvents <- ev - if ev.Event.EventType == event.Shutdown { - return - } - } + log.Infof("Launching Forwarding Goroutine") + // TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine + for { + e := q.Next() + ev := EventProfileEnvelope{Event: e, Profile: onion} + eh.profileEvents <- ev + if ev.Event.EventType == event.Shutdown { + return + } + } } // Push pushes an event onto the app event bus // It is also a way for libCwtch-go to publish an event for consumption by a UI before a Cwtch app has been initialized // use: to signal an error before a cwtch app could be created func (eh *EventHandler) Push(newEvent event.Event) { - eh.appBusQueue.Publish(newEvent) + eh.appBusQueue.Publish(newEvent) } func getLastMessageTime(conversationMessages []model.ConversationMessage) int { - if len(conversationMessages) == 0 { - return 0 - } - time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) - if err != nil { - return 0 - } - return int(time.Unix()) + if len(conversationMessages) == 0 { + return 0 + } + time, err := time.Parse(time.RFC3339Nano, conversationMessages[0].Attr[constants.AttrSentTimestamp]) + if err != nil { + return 0 + } + return int(time.Unix()) } // handleImagePreviews checks settings and, if appropriate, auto-downloads any images func handleImagePreviews(profile peer.CwtchPeer, ev *event.Event, conversationID, senderID int) { - settings := ReadGlobalSettings() - fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) + settings := ReadGlobalSettings() + fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) - // Short-circuit if file sharing is disabled - if err != nil { - return - } + // Short-circuit if file sharing is disabled + if err != nil { + return + } - // Short-circuit failures - // Don't autodownload images if the download path does not exist. - if settings.DownloadPath == "" { - return - } + // Short-circuit failures + // Don't autodownload images if the download path does not exist. + if settings.DownloadPath == "" { + return + } - // Don't autodownload images if the download path does not exist. - if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { - return - } + // Don't autodownload images if the download path does not exist. + if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { + return + } - // Now look at the image preview experiment - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if imagePreviewsEnabled { - var cm model.MessageWrapper - err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) - if err == nil && cm.Overlay == model.OverlayFileSharing { - var fm filesharing.OverlayMessage - err = json.Unmarshal([]byte(cm.Data), &fm) - if err == nil { - if fm.ShouldAutoDL() { - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) - log.Debugf("autodownloading file!") - ev.Data["Auto"] = constants.True - mID, _ := strconv.Atoi(ev.Data["Index"]) - profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) - fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) - } - } - } - } + // Now look at the image preview experiment + imagePreviewsEnabled := settings.Experiments["filesharing-images"] + if imagePreviewsEnabled { + var cm model.MessageWrapper + err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm) + if err == nil && cm.Overlay == model.OverlayFileSharing { + var fm filesharing.OverlayMessage + err = json.Unmarshal([]byte(cm.Data), &fm) + if err == nil { + if fm.ShouldAutoDL() { + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false) + log.Debugf("autodownloading file!") + ev.Data["Auto"] = constants.True + mID, _ := strconv.Atoi(ev.Data["Index"]) + profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) + fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes) + } + } + } + } }