Official cwtch.im peer and server implementations.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package server
  2. import (
  3. //"crypto/rsa"
  4. "git.mascherari.press/cwtch/server/fetch"
  5. "git.mascherari.press/cwtch/server/listen"
  6. "git.mascherari.press/cwtch/server/send"
  7. "git.mascherari.press/cwtch/storage"
  8. "github.com/s-rah/go-ricochet/application"
  9. "github.com/s-rah/go-ricochet/channels"
  10. "github.com/s-rah/go-ricochet/utils"
  11. "log"
  12. //"time"
  13. )
  14. type Server struct {
  15. }
  16. func (s *Server) Run(privateKeyFile string) {
  17. cwtchserver := new(application.RicochetApplication)
  18. pk, err := utils.LoadPrivateKeyFromFile(privateKeyFile)
  19. if err != nil {
  20. log.Fatalf("error reading private key file: %v", err)
  21. }
  22. l, err := application.SetupOnion("127.0.0.1:9051", "tcp4", "", pk, 9878)
  23. if err != nil {
  24. log.Fatalf("error setting up onion service: %v", err)
  25. }
  26. af := application.ApplicationInstanceFactory{}
  27. af.Init()
  28. ms := new(storage.MessageStore)
  29. ms.Init("cwtch.messages")
  30. af.AddHandler("im.cwtch.server.listen", func(rai *application.ApplicationInstance) func() channels.Handler {
  31. si := new(Instance)
  32. si.Init(rai, cwtchserver, ms)
  33. return func() channels.Handler {
  34. cslc := new(listen.CwtchServerListenChannel)
  35. return cslc
  36. }
  37. })
  38. af.AddHandler("im.cwtch.server.fetch", func(rai *application.ApplicationInstance) func() channels.Handler {
  39. si := new(Instance)
  40. si.Init(rai, cwtchserver, ms)
  41. return func() channels.Handler {
  42. cssc := new(fetch.CwtchServerFetchChannel)
  43. cssc.Handler = si
  44. return cssc
  45. }
  46. })
  47. af.AddHandler("im.cwtch.server.send", func(rai *application.ApplicationInstance) func() channels.Handler {
  48. si := new(Instance)
  49. si.Init(rai, cwtchserver, ms)
  50. return func() channels.Handler {
  51. cssc := new(send.CwtchServerSendChannel)
  52. cssc.Handler = si
  53. return cssc
  54. }
  55. })
  56. cwtchserver.Init(pk, af, new(application.AcceptAllContactManager))
  57. log.Printf("cwtch server running on cwtch:%s", l.Addr().String()[0:16])
  58. cwtchserver.Run(l)
  59. }