├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── development_task.md
│ ├── feature_request.md
│ └── support.md
└── pull_request_template.md
├── .gitignore
├── CONTRIBUTING.md
├── Dockerfile
├── INSTALL.md
├── LICENSE
├── LICENSE-APACHE
├── Makefile
├── README.md
├── adapter
└── adapter.go
├── appservice
├── applicationservice.go
├── consumers
│ └── roomserver.go
├── types
│ └── types.go
└── workers
│ └── transaction_scheduler.go
├── bgmgr
├── bgmgr.go
├── devicemgr
│ └── devicemgr.go
└── txnmgr
│ └── txnmgr.go
├── build.sh
├── cache
├── base.go
├── helper.go
├── local_cache.go
├── lock.go
├── redis_cache.go
├── roomalias.go
├── roomstate.go
├── token.go
├── txnid.go
└── userroommembership.go
├── cachewriter
├── cachewriter.go
└── consumers
│ ├── account_dbev_consumer.go
│ ├── consumer.go
│ ├── consumer_interface.go
│ ├── device_dbev_consumer.go
│ ├── e2e_dbev_consumer.go
│ ├── presence_dbev_consumer.go
│ ├── push_dbev_consumer.go
│ └── room_dbev_consumer.go
├── clientapi
├── README.md
├── api
│ ├── api.go
│ └── updatedomain.go
├── clientapi.go
├── consumer
│ └── consumer.go
├── handlers
│ ├── auth.go
│ ├── device.go
│ ├── keys.go
│ ├── media.go
│ ├── roomalias.go
│ ├── roomedu.go
│ ├── roomput.go
│ ├── roomqry.go
│ └── sync.go
├── httputil
│ └── httputil.go
├── routing
│ ├── account_data.go
│ ├── createroom.go
│ ├── device.go
│ ├── directory.go
│ ├── domain.go
│ ├── filter.go
│ ├── joinroom.go
│ ├── login.go
│ ├── logout.go
│ ├── membership.go
│ ├── newtoken.go
│ ├── postevent.go
│ ├── presence.go
│ ├── profile.go
│ ├── redactevent.go
│ ├── register.go
│ ├── room.go
│ ├── roomtags.go
│ ├── threepid.go
│ ├── userinfo.go
│ └── voip.go
├── rpc
│ └── profile.go
└── threepid
│ ├── invites.go
│ └── threepid.go
├── cmd
├── content
│ └── main.go
├── engine-server
│ ├── entry
│ │ ├── apiGateway.go
│ │ ├── appService.go
│ │ ├── cacheLoader.go
│ │ ├── dbupdate.go
│ │ ├── dendrite.go
│ │ ├── entry.go
│ │ ├── fronServer.go
│ │ ├── monolithServer.go
│ │ ├── persistServer.go
│ │ ├── profileRecover.go
│ │ ├── pushSender.go
│ │ ├── redirectStderr_darwin.go
│ │ ├── redirectStderr_linux.go
│ │ ├── redirectStderr_windows.go
│ │ ├── syncAggregate.go
│ │ ├── syncMonolith.go
│ │ ├── syncServer.go
│ │ ├── syncWriter.go
│ │ ├── tokenRewrite.go
│ │ ├── traceutils_test.go
│ │ └── version.go
│ └── main.go
├── federation
│ └── main.go
├── kafka-test
│ └── main.go
└── stress
│ ├── createRoom.go
│ ├── invite.go
│ ├── login.go
│ └── main.go
├── common
├── apiconsumer
│ └── apiconsumer.go
├── auth.go
├── basecomponent
│ ├── base.go
│ └── flags.go
├── code.go
├── complexCache.go
├── config
│ ├── appservice.go
│ └── config.go
├── databaseMng.go
├── domain
│ └── domainMng.go
├── encryption
│ └── encryption.go
├── eventcontent.go
├── events.go
├── feddomains.go
├── fetch
│ └── fetch.go
├── filter
│ ├── IFilterLoad.go
│ ├── SimpleFilterMng.go
│ └── filterMng.go
├── httpapi.go
├── jsonerror
│ ├── jsonerror.go
│ └── jsonerror_test.go
├── keydb
│ ├── keydb.go
│ ├── keyring.go
│ └── server_key_table.go
├── lifecycle
│ └── lifecycle.go
├── rpc.go
├── settings.go
├── sql.go
├── traceutils.go
├── transportMng.go
├── uid
│ ├── snowflake.go
│ └── uidGeneratorMng.go
├── util.go
└── utils
│ └── utils.go
├── config
├── as-registration.yaml
└── config.yaml
├── content
├── download
│ └── consumer.go
├── entry.go
├── repos
│ └── downloadStateRepo.go
├── routing
│ ├── emote.go
│ ├── processor.go
│ └── routing.go
├── storage
│ ├── implements
│ │ ├── content
│ │ │ ├── content.go
│ │ │ └── media_download_table.go
│ │ └── init.go
│ └── model
│ │ └── contentDB.go
└── version.go
├── core
├── IChannel.go
├── IConfig.go
├── IMessage.go
├── IMultiplexer.go
├── IProcessor.go
├── ISelector.go
└── ITransport.go
├── dbupdates
├── consumers
│ ├── cache_update_consumer.go
│ ├── cache_update_manager.go
│ ├── dbev_seq_consumer.go
│ └── dbev_seq_manager.go
├── dbregistry
│ └── dbregistry.go
├── dbupdates.go
├── dbupdatetypes
│ └── types.go
└── processors
│ ├── account
│ ├── account_accounts.go
│ ├── account_data.go
│ ├── account_filter.go
│ ├── account_profiles.go
│ ├── account_user_info.go
│ └── room_tags.go
│ ├── device
│ ├── device_devices.go
│ └── mig_device_devices.go
│ ├── encryptapi
│ ├── encrypt_algorithm.go
│ ├── encrypt_device_key.go
│ └── encrypt_onetime_key.go
│ ├── init.go
│ ├── presence
│ └── presence_presences.go
│ ├── publicroomsapi
│ └── publicroomsapi_public_rooms.go
│ ├── pushapi
│ ├── push_rules.go
│ ├── push_rules_enable.go
│ └── pushers.go
│ ├── roomserver
│ ├── roomserver_event_json.go
│ ├── roomserver_events.go
│ ├── roomserver_invites.go
│ ├── roomserver_membership.go
│ ├── roomserver_room_aliases.go
│ ├── roomserver_room_domains.go
│ ├── roomserver_rooms.go
│ ├── roomserver_settings.go
│ └── roomserver_state_snapshots.go
│ ├── sqlutil
│ └── util.go
│ └── syncapi
│ ├── syncapi_client_data_stream.go
│ ├── syncapi_current_room_state.go
│ ├── syncapi_key_change_stream.go
│ ├── syncapi_output_min_stream.go
│ ├── syncapi_output_room_events.go
│ ├── syncapi_presence_data_stream.go
│ ├── syncapi_receipt_data_stream.go
│ ├── syncapi_send_to_device.go
│ ├── syncapi_user_receipt_data.go
│ └── syncapi_user_time_line.go
├── dbwriter
├── consumers
│ ├── account_dbev_consumer.go
│ ├── consumer.go
│ ├── consumer_interface.go
│ ├── device_dbev_consumer.go
│ ├── e2e_dbev_consumer.go
│ ├── presence_dbev_consumer.go
│ ├── public_room_dbev_consumer.go
│ ├── push_dbev_consumer.go
│ ├── room_dbev_consumer.go
│ └── sync_dbev_consumer.go
└── dbwriter.go
├── docker-compose.yaml
├── docs
└── dev
│ └── git
│ ├── contribution_dev_process.jpg
│ ├── git.md
│ ├── git_clean.jpg
│ ├── ligase_dev_circle.jpg
│ ├── ligase_dev_notes.jpg
│ ├── ligase_dev_release_notes.jpg
│ └── ligase_release_proc.jpg
├── encryptoapi
├── api
│ └── api.go
├── encryptoapi.go
└── routing
│ └── keys.go
├── federation
├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
├── build.sh
├── client
│ ├── cert
│ │ └── cert.go
│ └── fedclient.go
├── config
│ └── config.go
├── docker-compose.yml
├── entry.go
├── fedbackfill
│ ├── fedbackfill.go
│ └── processor.go
├── federationapi
│ ├── entry
│ │ ├── auth.go
│ │ ├── backfill.go
│ │ ├── entry.go
│ │ ├── events.go
│ │ ├── invite.go
│ │ ├── join.go
│ │ ├── keys.go
│ │ ├── leave.go
│ │ ├── notice.go
│ │ ├── profile.go
│ │ ├── query.go
│ │ ├── rooms.go
│ │ ├── send.go
│ │ └── userinfo.go
│ ├── federationapi.go
│ └── rpc
│ │ ├── fedPublicRoomsRpcClient.go
│ │ └── fedRpcClient.go
├── fedmissing
│ └── get_missing_events.go
├── fedreq
│ ├── federation.go
│ └── rpc
│ │ ├── common.go
│ │ ├── profile.go
│ │ └── room.go
├── fedsender
│ ├── edusender.go
│ ├── feddispatch.go
│ ├── fedsender.go
│ └── queue
│ │ ├── destinationqueue.go
│ │ └── queue.go
├── fedsync
│ ├── fedsync.go
│ └── syncconsumer
│ │ ├── consumer.go
│ │ ├── download.go
│ │ ├── invite.go
│ │ ├── join.go
│ │ ├── leave.go
│ │ ├── profile.go
│ │ └── roomAlias.go
├── fedutil
│ ├── netdisk.go
│ └── notary.go
├── model
│ ├── backfilltypes
│ │ └── backfillProc.go
│ └── repos
│ │ ├── backfillRepo.go
│ │ ├── joinRoomsRepo.go
│ │ └── sendRecRepo.go
├── run-fed1.sh
├── run-fed2.sh
├── run.sh
├── storage
│ ├── implements
│ │ ├── federation
│ │ │ ├── backfill_record_table.go
│ │ │ ├── federation.go
│ │ │ ├── joined_rooms_table.go
│ │ │ ├── missing_events_table.go
│ │ │ └── send_record_table.go
│ │ └── init.go
│ └── model
│ │ └── federationDB.go
└── version.go
├── go.mod
├── go.sum
├── logo
├── ligase_100_320.png
├── ligase_100_320a.png
├── ligase_480_480.png
└── ligase_480_480a.png
├── model
├── LICENSE
├── README.md
├── authtypes
│ ├── account.go
│ ├── device.go
│ ├── logintypes.go
│ ├── presence.go
│ └── profile.go
├── base_mode.go
├── dbtypes
│ ├── account_dbev.go
│ ├── db.go
│ ├── device_dbev.go
│ ├── e2e_dbev.go
│ ├── presence_dbev.go
│ ├── public_room_dbev.go
│ ├── push_dbev.go
│ ├── room_dbev.go
│ └── sync_dbev.go
├── error.go
├── feedstypes
│ ├── Ifeed.go
│ ├── clientDataStream.go
│ ├── eventReadStream.go
│ ├── keyChangeStream.go
│ ├── presenceDataStream.go
│ ├── receiptDataStream.go
│ ├── stdEventStream.go
│ ├── streamEvent.go
│ ├── timeLineEvent.go
│ └── timeline.go
├── gob_message.go
├── mediatypes
│ └── types.go
├── model_test.go
├── noticetypes
│ └── notice.go
├── publicroomstypes
│ └── types.go
├── pushapitypes
│ └── types.go
├── repos
│ ├── clientDataStreamRepo.go
│ ├── displayNameRepo.go
│ ├── eventReadStreamRepo.go
│ ├── keyChangeStreamRepo.go
│ ├── lru.go
│ ├── onlineUserRepo.go
│ ├── presenceDataStreamRepo.go
│ ├── readCountRepo.go
│ ├── receiptDataStreamRepo.go
│ ├── roomHistoryTimelineRepo.go
│ ├── roomStateRepo.go
│ ├── roomStateTimelineRepo.go
│ ├── roomserverStateRepo.go
│ ├── roomserverUserMembershipRepo.go
│ ├── stdEventStreamRepo.go
│ ├── timelineRepo.go
│ ├── userDeviceActiveRepo.go
│ ├── userReceiptRepo.go
│ └── userTimeLineRepo.go
├── roomservertypes
│ └── types.go
├── service
│ ├── cache.go
│ ├── publicroomsapi
│ │ └── query.go
│ └── roomserverapi
│ │ ├── alias.go
│ │ ├── edu.go
│ │ ├── input.go
│ │ ├── output.go
│ │ ├── query.go
│ │ └── rpc.go
├── syncapitypes
│ └── types.go
├── types
│ ├── common.go
│ ├── keys.go
│ ├── rcs.go
│ ├── storage.go
│ └── upload.go
└── version.go
├── plugins
├── channel
│ ├── kafkaChannel.go
│ └── natsChannel.go
├── init.go
├── message
│ ├── coder.go
│ ├── external
│ │ ├── README.md
│ │ ├── accounAdmin.go
│ │ ├── accountAdmin.capn
│ │ ├── accountAdmin.capn.go
│ │ ├── device.capn
│ │ ├── device.capn.go
│ │ ├── device.go
│ │ ├── events.capn
│ │ ├── events.capn.go
│ │ ├── events.go
│ │ ├── federation.go
│ │ ├── filter.capn
│ │ ├── filter.capn.go
│ │ ├── filter.go
│ │ ├── login.capn
│ │ ├── login.capn.go
│ │ ├── login.go
│ │ ├── modules.capn
│ │ ├── modules.capn.go
│ │ ├── modules.go
│ │ ├── presence.capn
│ │ ├── presence.capn.go
│ │ ├── presence.go
│ │ ├── profile.capn
│ │ ├── profile.capn.go
│ │ ├── profile.go
│ │ ├── rcs.go
│ │ ├── register.capn
│ │ ├── register.capn.go
│ │ ├── register.go
│ │ ├── requestDecode.go
│ │ ├── requestEncode.go
│ │ ├── responseDecode.go
│ │ ├── responseEncode.go
│ │ ├── room.capn
│ │ ├── room.capn.go
│ │ ├── room.go
│ │ ├── serverCfg.go
│ │ ├── setting.go
│ │ ├── userData.capn
│ │ ├── userData.capn.go
│ │ ├── userData.go
│ │ ├── userinfo.go
│ │ ├── util.go
│ │ ├── visibilityrange.go
│ │ └── voip.go
│ └── internals
│ │ ├── capn_test.go
│ │ ├── msg.capnp
│ │ ├── msg.capnp.go
│ │ └── msgdef.go
├── multiplexer
│ ├── processorMultiplexer.go
│ └── transportMultiplexer.go
├── processors
│ ├── HandlerProcessor.go
│ └── InputProcessor.go
├── selector
│ ├── consistent.go
│ └── consistentWithBoundedLoads.go
└── transport
│ ├── baseTransport.go
│ ├── consumersMon.go
│ ├── kafkaTransport.go
│ └── natsTransport.go
├── proxy
├── api
│ ├── fed_api.go
│ └── media_api.go
├── bridge
│ └── bridge.go
├── consumers
│ ├── filter_token.go
│ └── verify_token.go
├── handler
│ └── notary.go
├── proxy.go
└── routing
│ ├── netdisk.go
│ ├── processor.go
│ └── routing.go
├── publicroomsapi
├── README.md
├── api
│ └── api.go
├── consumers
│ └── roomserver.go
├── directory
│ └── public_rooms.go
├── publicroomsapi.go
└── rpc
│ └── publicRoomsRpc.go
├── pushapi
├── api
│ └── api.go
├── pushapi.go
└── routing
│ ├── baserules.go
│ ├── push_rules.go
│ └── pushers.go
├── pushsender
├── consumers
│ └── pushDataClient.go
└── pushSender.go
├── rcsserver
├── api
│ ├── api.go
│ └── consumer.go
├── processors
│ ├── event_processor.go
│ ├── event_processor_test.go
│ └── util.go
├── rcsserver.go
└── rpc
│ └── event.go
├── roomserver
├── README.md
├── consumers
│ ├── clientapi.go
│ ├── dismissRoom.go
│ └── queryApi.go
├── processors
│ ├── aliasProcessor.go
│ ├── eventProcessor.go
│ ├── fedProcessor.go
│ └── roomQryProcessor.go
├── roomserver.go
└── rpc
│ ├── roomAliasRpc.go
│ ├── roomRpcClient.go
│ └── roomServerRpc.go
├── skunkworks
├── gomatrix
│ ├── LICENSE
│ ├── README.md
│ ├── client.go
│ ├── client_examples_test.go
│ ├── client_test.go
│ ├── events.go
│ ├── filter.go
│ ├── hooks
│ │ ├── install.sh
│ │ └── pre-commit
│ ├── requests.go
│ ├── responses.go
│ ├── room.go
│ ├── store.go
│ ├── sync.go
│ ├── userids.go
│ ├── userids_examples_test.go
│ └── userids_test.go
├── gomatrixserverlib
│ ├── LICENSE
│ ├── README.md
│ ├── appservice.go
│ ├── base64.go
│ ├── base64_test.go
│ ├── client.go
│ ├── clientevent.go
│ ├── clientevent_test.go
│ ├── edu.go
│ ├── event.go
│ ├── event_examples_test.go
│ ├── event_test.go
│ ├── eventauth.go
│ ├── eventauth_test.go
│ ├── eventcontent.go
│ ├── eventcontent_test.go
│ ├── eventcrypto.go
│ ├── eventcrypto_test.go
│ ├── federationclient.go
│ ├── federationtypes.go
│ ├── federationtypes_test.go
│ ├── filter.go
│ ├── hex_string.go
│ ├── hex_string_test.go
│ ├── hooks
│ │ ├── install.sh
│ │ └── pre-commit
│ ├── json.go
│ ├── json_test.go
│ ├── keyring.go
│ ├── keyring_test.go
│ ├── keys.go
│ ├── linter.json
│ ├── redactevent.go
│ ├── request.go
│ ├── request_test.go
│ ├── resolve.go
│ ├── signing.go
│ ├── signing_test.go
│ ├── stateresolution.go
│ ├── stateresolution_test.go
│ ├── timestamp.go
│ ├── tokens
│ │ ├── tokens.go
│ │ ├── tokens_handlers.go
│ │ ├── tokens_handlers_test.go
│ │ └── tokens_test.go
│ ├── transaction.go
│ └── travis.sh
├── gomatrixutil
│ ├── LICENSE
│ ├── README.md
│ ├── context.go
│ ├── hooks
│ │ ├── install.sh
│ │ └── pre-commit
│ ├── json.go
│ ├── json_test.go
│ ├── unique.go
│ └── unique_test.go
├── log
│ ├── log.go
│ ├── log_test.go
│ ├── logger.go
│ └── zapLogger.go
├── monitor
│ └── go-client
│ │ ├── README.md
│ │ ├── httpmonitor
│ │ └── httpmonitor.go
│ │ └── monitor
│ │ ├── counter.go
│ │ ├── gauge.go
│ │ ├── histogram.go
│ │ ├── interface.go
│ │ ├── observer.go
│ │ ├── prometheus.go
│ │ ├── summary.go
│ │ └── timer.go
├── util
│ ├── LICENSE
│ ├── README.md
│ ├── cas
│ │ ├── atom.go
│ │ ├── doc.go
│ │ └── mutex.go
│ ├── id
│ │ ├── id.go
│ │ └── id_test.go
│ ├── pacakge.go
│ └── workerpool
│ │ ├── worker.go
│ │ ├── workerpool.go
│ │ └── wp_test.go
└── zap
│ ├── CHANGELOG.md
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ ├── FAQ.md
│ ├── LICENSE.txt
│ ├── Makefile
│ ├── README.md
│ ├── array.go
│ ├── array_test.go
│ ├── buffer
│ ├── buffer.go
│ ├── buffer_test.go
│ ├── pool.go
│ └── pool_test.go
│ ├── check_license.sh
│ ├── common_test.go
│ ├── config.go
│ ├── config_test.go
│ ├── doc.go
│ ├── encoder.go
│ ├── encoder_test.go
│ ├── error.go
│ ├── error_test.go
│ ├── example_test.go
│ ├── field.go
│ ├── field_test.go
│ ├── flag.go
│ ├── flag_test.go
│ ├── glide.lock
│ ├── glide.yaml
│ ├── global.go
│ ├── global_test.go
│ ├── http_handler.go
│ ├── http_handler_test.go
│ ├── internal
│ ├── bufferpool
│ │ └── bufferpool.go
│ ├── color
│ │ ├── color.go
│ │ └── color_test.go
│ ├── exit
│ │ ├── exit.go
│ │ └── exit_test.go
│ └── readme
│ │ └── readme.go
│ ├── level.go
│ ├── level_test.go
│ ├── logger.go
│ ├── logger_bench_test.go
│ ├── logger_test.go
│ ├── options.go
│ ├── scripts
│ └── cover.sh
│ ├── stacktrace.go
│ ├── stacktrace_ext_test.go
│ ├── stacktrace_test.go
│ ├── sugar.go
│ ├── sugar_test.go
│ ├── time.go
│ ├── time_test.go
│ ├── writer.go
│ ├── writer_test.go
│ ├── zapcore
│ ├── console_encoder.go
│ ├── console_encoder_bench_test.go
│ ├── core.go
│ ├── core_test.go
│ ├── doc.go
│ ├── encoder.go
│ ├── encoder_test.go
│ ├── entry.go
│ ├── entry_test.go
│ ├── error.go
│ ├── error_test.go
│ ├── field.go
│ ├── field_test.go
│ ├── hook.go
│ ├── hook_test.go
│ ├── json_encoder.go
│ ├── json_encoder_bench_test.go
│ ├── json_encoder_impl_test.go
│ ├── level.go
│ ├── level_strings.go
│ ├── level_strings_test.go
│ ├── level_test.go
│ ├── marshaler.go
│ ├── memory_encoder.go
│ ├── memory_encoder_test.go
│ ├── sampler.go
│ ├── sampler_bench_test.go
│ ├── sampler_test.go
│ ├── tee.go
│ ├── tee_logger_bench_test.go
│ ├── tee_test.go
│ ├── write_syncer.go
│ ├── write_syncer_bench_test.go
│ └── write_syncer_test.go
│ ├── zapgrpc
│ ├── zapgrpc.go
│ └── zapgrpc_test.go
│ └── zaptest
│ ├── doc.go
│ ├── observer
│ ├── logged_entry.go
│ ├── logged_entry_test.go
│ ├── observer.go
│ └── observer_test.go
│ ├── timeout.go
│ └── writer.go
├── start.sh
├── storage
├── implements
│ ├── accounts
│ │ ├── accdata_table.go
│ │ ├── accounts_table.go
│ │ ├── filter_table.go
│ │ ├── profile_table.go
│ │ ├── room_tags_table.go
│ │ ├── storage.go
│ │ └── user_info_table.go
│ ├── appservice
│ │ ├── appservice_events_table.go
│ │ ├── storage.go
│ │ └── txn_id_counter_table.go
│ ├── configdb
│ │ ├── config_db_table.go
│ │ ├── configdb.go
│ │ └── server_instance_table.go
│ ├── devices
│ │ ├── devices_table.go
│ │ ├── mig_devices_table.go
│ │ └── storage.go
│ ├── encryptoapi
│ │ ├── encrypt_algorithm.go
│ │ ├── encrypt_devicekey_table.go
│ │ ├── encrypt_onetimekey_table.go
│ │ └── storage.go
│ ├── init.go
│ ├── keydb
│ │ ├── cert_table.go
│ │ ├── keydb.go
│ │ ├── keyring.go
│ │ └── server_key_table.go
│ ├── presence
│ │ ├── presence_table.go
│ │ └── storage.go
│ ├── publicroomapi
│ │ ├── prepare.go
│ │ ├── public_rooms_table.go
│ │ └── storage.go
│ ├── pushapi
│ │ ├── push_rules_enable.go
│ │ ├── push_rules_table.go
│ │ ├── pushers_table.go
│ │ └── storage.go
│ ├── rcs_server
│ │ ├── friendship.go
│ │ ├── prepare.go
│ │ ├── sql.go
│ │ └── storage.go
│ ├── roomserver
│ │ ├── event_json_table.go
│ │ ├── events_table.go
│ │ ├── invite_table.go
│ │ ├── membership_table.go
│ │ ├── prepare.go
│ │ ├── room_aliases_table.go
│ │ ├── room_domains_table.go
│ │ ├── rooms_table.go
│ │ ├── settings.go
│ │ ├── sql.go
│ │ ├── state_snapshot_table.go
│ │ └── storage.go
│ └── syncapi
│ │ ├── client_data_table.go
│ │ ├── current_room_state_table.go
│ │ ├── key_change_extension.go
│ │ ├── output_min_stream_table.go
│ │ ├── output_room_events_table.go
│ │ ├── presence_data_table.go
│ │ ├── receipt_data_table.go
│ │ ├── send_to_device_table.go
│ │ ├── syncserver.go
│ │ ├── user_receipt_data_table.go
│ │ └── user_time_line_table.go
└── model
│ ├── DBmonitor.go
│ ├── accountsDB.go
│ ├── appServiceDB.go
│ ├── configDB.go
│ ├── deviceDB.go
│ ├── encryptorAPIDB.go
│ ├── keyDB.go
│ ├── model_test.go
│ ├── presenceDB.go
│ ├── publicRoomAPIDB.go
│ ├── pushAPIDB.go
│ ├── rcs_db.go
│ ├── roomServerDB.go
│ └── syncAPIDB.go
├── syncaggregate
├── api
│ ├── consumer.go
│ ├── devicestate.go
│ ├── eventWithID.go
│ ├── events.go
│ ├── initialSync.go
│ ├── joinRooms.go
│ ├── keysChanges.go
│ ├── reportRoom.go
│ ├── sendToDevice.go
│ ├── sync.go
│ └── userUnread.go
├── consumers
│ ├── actdata.go
│ ├── consumer.go
│ ├── profile.go
│ └── typing.go
├── rpc
│ ├── event.go
│ ├── joinedroom.go
│ ├── keychange.go
│ ├── keyupdate.go
│ ├── presence.go
│ ├── receiptupdate.go
│ ├── sendtodevice.go
│ ├── sync.go
│ ├── typing.go
│ └── unread.go
├── sync
│ ├── syncLoad.go
│ ├── syncMng.go
│ ├── syncRequest.go
│ └── syncResponse.go
└── syncaggregate.go
├── syncserver
├── api
│ ├── consumer.go
│ ├── roomEventContext.go
│ ├── roomInitialSync.go
│ ├── roomMember.go
│ ├── roomMessages.go
│ ├── roomReadMarkers.go
│ ├── roomReceipt.go
│ ├── roomState.go
│ ├── roomStateByType.go
│ ├── roomStateByTypeAndKey.go
│ ├── systemManager.go
│ ├── typing.go
│ └── visibilityRange.go
├── consumers
│ ├── feedserver.go
│ ├── profile.go
│ ├── push.go
│ ├── receipt.go
│ └── syncServer.go
├── extra
│ ├── extra.go
│ └── hint.go
├── rpc
│ ├── receipt.go
│ ├── sync.go
│ ├── typing.go
│ └── unread.go
└── syncserver.go
├── syncwriter
├── consumers
│ └── consumer.go
└── syncwriter.go
└── tokenrewrite
├── rpc
└── token.go
├── storage
├── devices_table.go
├── tokenrewrite_storage.go
├── tokens_table.go
└── users_table.go
└── tokenrewrite.go
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F41B Bug Report"
3 | about: As a User, I want to report a Bug.
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Bug Report
11 |
12 | Please answer these questions before submitting your issue. Thanks!
13 |
14 | ### 1. Minimal reproduce step (Required)
15 |
16 |
17 |
18 | ### 2. What did you expect to see? (Required)
19 |
20 | ### 3. What did you see instead (Required)
21 |
22 | ### 4. Affected version (Required)
23 |
24 |
25 |
26 | ### 5. Root Cause Analysis
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/development_task.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F680 Development Task"
3 | about: As a Ligase developer, I want to record a development task.
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Development Task
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F680 Feature Request"
3 | about: As a user, I want to request a New Feature on the product.
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Feature Request
11 |
12 | **Is your feature request related to a problem? Please describe:**
13 |
14 |
15 | **Describe the feature you'd like:**
16 |
17 |
18 | **Describe alternatives you've considered:**
19 |
20 |
21 | **Teachability, Documentation, Adoption, Migration Strategy:**
22 |
23 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/support.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F914 Ask a Question"
3 | about: I want to ask a question.
4 | labels: question
5 | ---
6 |
7 | ## Question
8 |
9 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ### Pull Request Checklist
2 |
3 |
4 |
5 | * [ ] Pull request is based on the develop branch
6 |
7 |
8 |
14 |
15 | ### What problem does this PR solve?
16 |
17 | Issue Number: close #xxx
18 |
19 | Problem Summary:
20 |
21 | ### What is changed and how it works?
22 |
23 | What's Changed:
24 |
25 | How it Works:
26 |
27 | ### Check List
28 |
29 | Tests
30 |
31 | - Unit test
32 | - Integration test
33 | - Manual test (add detailed scripts or steps below)
34 | - No code
35 |
36 | Side effects
37 |
38 | - Performance regression
39 | - Consumes more CPU
40 | - Consumes more MEM
41 | - Breaking backward compatibility
42 |
43 | ### Release note
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries for programs and plugins
2 | *.exe
3 | *.exe~
4 | *.dll
5 | *.so
6 | *.dylib
7 |
8 | # Test binary, built with `go test -c`
9 | *.test
10 |
11 | # Output of the go coverage tool, specifically when used with LiteIDE
12 | *.out
13 |
14 | # Dependency directories (remove the comment below to include it)
15 | # vendor/
16 |
17 | bin
18 | .vscode
19 | log
20 | .DS_Store
21 | .idea
22 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine
2 |
3 | RUN mkdir -p /mnt/data/logs
4 | RUN mkdir -p /opt/ligase/log
5 | #RUN apk add --update-cache ca-certificates
6 | RUN apk add librdkafka
7 | ENV LOG_DIR=/mnt/data/logs
8 |
9 | ENV SERVICE_NAME=monolith
10 |
11 | ADD ./config /opt/ligase/config
12 | ADD ./bin /opt/ligase/bin
13 | ADD ./start.sh /opt/ligase/start.sh
14 |
15 | #EXPOSE 8008 8448 7000
16 | EXPOSE 8008 8448 7000 18008 18448
17 |
18 | WORKDIR /opt/ligase
19 | CMD ./start.sh
20 |
--------------------------------------------------------------------------------
/INSTALL.md:
--------------------------------------------------------------------------------
1 | # Installing Ligase
2 |
3 | Ligase is designed to be a Cloud Native application. We recommend deploy Ligase via docker.
4 |
5 | This document shows how to start up Ligase on a single machine
6 |
7 | ## Requirements
8 |
9 | * Go 1.13 or higher
10 | * Postgres 9.5 or higher
11 | * Apache Kafka 0.10.2+
12 |
13 | ## Setup denpendent services
14 | recommended way:
15 |
16 | ```bash
17 | docker-compose up -d
18 | ```
19 |
20 | ## Build
21 |
22 | ### Build for docker
23 |
24 | ```bash
25 | ./build.sh
26 | docker build -t ligase .
27 | ```
28 |
29 | ### Build for local host
30 |
31 | ```bash
32 | ./build.sh
33 | ```
34 |
35 | add those to **/etc/hosts** if you want to run ligase in your local host.
36 |
37 | ```shell
38 | 127.0.0.1 pg-master
39 | 127.0.0.1 zookeeper
40 | 127.0.0.1 kafka
41 | 127.0.0.1 redis
42 | 127.0.0.1 nats
43 | ```
44 |
45 | ## Configuration
46 |
47 | Replace ./config/config.yaml with your own configuration if you didn't use the recommended way to setup denpendent services.
48 |
49 |
50 | ## Run
51 |
52 | ## Run in docker
53 |
54 | ```sh
55 | docker run --network ligase_default --expose 8008 --detach --name ligase ligase
56 | ```
57 |
58 | ### Run in local host
59 |
60 | 1. In order to run ligase in your local host, follow the steps in https://github.com/edenhill/librdkafka to install librdkafka first.
61 |
62 | 2. Then start ligase by:
63 |
64 | ```sh
65 | export SERVICE_NAME=monolith
66 | ./start.sh
67 | ```
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | test:
2 | @echo "test passed"
3 |
4 | check:
5 |
6 | fmt:
7 | @echo "gofmt (simplify)"
8 | go fmt ./...
9 |
--------------------------------------------------------------------------------
/bgmgr/bgmgr.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package bgmgr
16 |
17 | import (
18 | "github.com/finogeeks/ligase/bgmgr/devicemgr"
19 | "github.com/finogeeks/ligase/bgmgr/txnmgr"
20 | "github.com/finogeeks/ligase/common"
21 | "github.com/finogeeks/ligase/common/filter"
22 | "github.com/finogeeks/ligase/model/service"
23 | "github.com/finogeeks/ligase/skunkworks/log"
24 | "github.com/finogeeks/ligase/storage/model"
25 | )
26 |
27 | func SetupBgMgrComponent(
28 | deviceDB model.DeviceDatabase,
29 | cache service.Cache,
30 | encryptDB model.EncryptorAPIDatabase,
31 | syncDB model.SyncAPIDatabase,
32 | rpcCli *common.RpcClient,
33 | tokenFilter *filter.Filter,
34 | scanUnActive int64,
35 | kickUnActive int64,
36 | ) {
37 | deviceMgr := devicemgr.NewDeviceMgr(deviceDB, cache, encryptDB, syncDB, rpcCli, tokenFilter, scanUnActive, kickUnActive)
38 | log.Infof("scantime:%d,kicktime:%d", scanUnActive, kickUnActive)
39 | deviceMgr.Start()
40 | txnMgr := txnmgr.NewTxnMgr(cache)
41 | txnMgr.Start()
42 | }
43 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | PROJDIR=`cd $(dirname $0); pwd -P`
4 | cd $PROJDIR
5 | echo `pwd`
6 |
7 | export GOPROXY=https://goproxy.io
8 |
9 | cd $PROJDIR/cmd/engine-server
10 | go build -v -o $PROJDIR/bin/engine-server
11 | cd $PROJDIR/cmd/federation
12 | go build -v -o $PROJDIR/bin/federation
13 | cd $PROJDIR/cmd/content
14 | go build -v -o $PROJDIR/bin/content
15 |
16 | cd $PROJDIR
17 | go mod tidy
--------------------------------------------------------------------------------
/cache/helper.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package cache
16 |
17 | import (
18 | "github.com/gomodule/redigo/redis"
19 | )
20 |
21 | func Int64(reply interface{}, err error) (int64, error) {
22 | return redis.Int64(reply, err)
23 | }
24 |
25 | func String(reply interface{}, err error) (string, error) {
26 | return redis.String(reply, err)
27 | }
28 |
29 | func Bool(reply interface{}, err error) (bool, error) {
30 | return redis.Bool(reply, err)
31 | }
32 |
--------------------------------------------------------------------------------
/cache/roomalias.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package cache
16 |
17 | import (
18 | "fmt"
19 | )
20 |
21 | func (rc *RedisCache) GetAlias(key string) (string, error) {
22 | key = fmt.Sprintf("roomalias:%s", key)
23 | return rc.GetString(key)
24 | }
25 |
26 | func (rc *RedisCache) SetAlias(key, val string, expire int64) error {
27 | key = fmt.Sprintf("roomalias:%s", key)
28 | return rc.Set(key, val, expire)
29 | }
30 |
31 | func (rc *RedisCache) AliasExists(key string) (bool, error) {
32 | key = fmt.Sprintf("roomalias:%s", key)
33 | return rc.Exists(key)
34 | }
35 |
36 | func (rc *RedisCache) DelAlias(key string) error {
37 | key = fmt.Sprintf("roomalias:%s", key)
38 | return rc.Del(key)
39 | }
40 |
--------------------------------------------------------------------------------
/cache/userroommembership.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package cache
16 |
17 | import (
18 | "fmt"
19 | )
20 |
21 | func (rc *RedisCache) SetUserRoomMemberShip(roomID, userID string, mType int64) error {
22 | key := fmt.Sprintf("membership:%s", userID)
23 | return rc.HSet(key, roomID, mType)
24 | }
25 |
26 | func (rc *RedisCache) SetUserRoomMemberShipMulti(userID string, memberships map[string]int64) error {
27 | key := fmt.Sprintf("membership:%s", userID)
28 | return rc.HMSet(key, memberships)
29 | }
30 |
31 | func (rc *RedisCache) GetUserRoomMemberShip(userID string) (map[string]int64, error) {
32 | key := fmt.Sprintf("membership:%s", userID)
33 | result, err := rc.HGetAll(key)
34 | if err != nil {
35 | return nil, err
36 | } else {
37 | if result == nil {
38 | return nil, nil
39 | }
40 | r := make(map[string]int64)
41 | for k, v := range result {
42 | r[k], _ = Int64(v, nil)
43 | }
44 | return r, nil
45 | }
46 | }
47 |
48 | func (rc *RedisCache) CheckUserRoomMemberShipExists(userID string) (bool, error) {
49 | key := fmt.Sprintf("membership:%s", userID)
50 | return rc.Exists(key)
51 | }
52 |
--------------------------------------------------------------------------------
/cachewriter/cachewriter.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package cachewriter
19 |
20 | import (
21 | "github.com/finogeeks/ligase/cachewriter/consumers"
22 | "github.com/finogeeks/ligase/common/basecomponent"
23 | "github.com/finogeeks/ligase/skunkworks/log"
24 | )
25 |
26 | func SetupCacheWriterComponent(
27 | base *basecomponent.BaseDendrite,
28 | ) {
29 | dbEvConsumer := consumers.NewDBEventCacheConsumer(base.Cfg)
30 |
31 | if err := dbEvConsumer.Start(); err != nil {
32 | log.Panicw("failed to start cache data consumer", log.KeysAndValues{"error", err})
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/cachewriter/consumers/consumer_interface.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package consumers
16 |
17 | import (
18 | "context"
19 | "github.com/finogeeks/ligase/common/config"
20 | "github.com/finogeeks/ligase/model/dbtypes"
21 | log "github.com/finogeeks/ligase/skunkworks/log"
22 | "github.com/gomodule/redigo/redis"
23 | "sync"
24 | )
25 |
26 | var regMu sync.RWMutex
27 | var newHandler = make(map[int64]func() ConsumerInterface)
28 |
29 | type ConsumerInterface interface {
30 | OnMessage(context.Context, *dbtypes.DBEvent) error
31 | Prepare(*config.Dendrite)
32 | SetPool(PoolProviderInterface)
33 | Start()
34 | }
35 |
36 | func Register(name int64, f func() ConsumerInterface) {
37 | regMu.Lock()
38 | defer regMu.Unlock()
39 |
40 | if f == nil {
41 | log.Panicf("Register: %s func nil", dbtypes.DBCategoryToStr(name))
42 | }
43 |
44 | if _, ok := newHandler[name]; ok {
45 | log.Panicf("Register: %s already registered", dbtypes.DBCategoryToStr(name))
46 | }
47 |
48 | newHandler[name] = f
49 | }
50 |
51 | type PoolProviderInterface interface {
52 | Pool() *redis.Pool
53 | }
54 |
--------------------------------------------------------------------------------
/clientapi/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/clientapi/README.md
--------------------------------------------------------------------------------
/clientapi/handlers/auth.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
17 | import (
18 | "context"
19 | "github.com/finogeeks/ligase/plugins/message/internals"
20 | log "github.com/finogeeks/ligase/skunkworks/log"
21 | )
22 |
23 | type AuthHandler struct {
24 | }
25 |
26 | func (auth *AuthHandler) ProcessInputMsg(ctx context.Context, msg *internals.InputMsg) {
27 | log.Infof("AuthHandler recv msg:%08x", msg.MsgType)
28 | switch msg.MsgType {
29 | case internals.MSG_GET_LOGIN:
30 | case internals.MSG_POST_LOGIN:
31 | case internals.MSG_POST_LOGOUT:
32 | case internals.MSG_POST_LOGOUT_ALL:
33 |
34 | case internals.MSG_POST_REGISTER:
35 | case internals.MSG_POST_REGISTER_EMAIL:
36 | case internals.MSG_POST_REGISTER_MSISDN:
37 | case internals.MSG_POST_ACCOUT_PASS:
38 | case internals.MSG_POST_ACCOUT_PASS_EMAIL:
39 | case internals.MSG_POST_ACCOUT_PASS_MSISDN:
40 | case internals.MSG_POST_ACCOUNT_DEACTIVATE:
41 | case internals.MSG_GET_REGISTER_AVAILABLE:
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/clientapi/handlers/device.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
--------------------------------------------------------------------------------
/clientapi/handlers/keys.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
--------------------------------------------------------------------------------
/clientapi/handlers/media.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
--------------------------------------------------------------------------------
/clientapi/handlers/roomalias.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
--------------------------------------------------------------------------------
/clientapi/handlers/roomedu.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
--------------------------------------------------------------------------------
/clientapi/handlers/roomput.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
--------------------------------------------------------------------------------
/clientapi/handlers/roomqry.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package handlers
16 |
--------------------------------------------------------------------------------
/clientapi/routing/threepid.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package routing
19 |
20 | import (
21 | "net/http"
22 |
23 | "github.com/finogeeks/ligase/core"
24 | "github.com/finogeeks/ligase/plugins/message/external"
25 | )
26 |
27 | // RequestEmailToken implements:
28 | // POST /account/3pid/email/requestToken
29 | // POST /register/email/requestToken
30 | func RequestEmailToken() (int, core.Coder) {
31 | return http.StatusOK, &external.PostAccount3PIDEmailResponse{}
32 | }
33 |
34 | // CheckAndSave3PIDAssociation implements POST /account/3pid
35 | func CheckAndSave3PIDAssociation() (int, core.Coder) {
36 | return http.StatusOK, nil
37 | }
38 |
39 | // GetAssociated3PIDs implements GET /account/3pid
40 | func GetAssociated3PIDs() (int, core.Coder) {
41 | return http.StatusOK, &external.GetThreePIDsResponse{[]external.ThreePID{}}
42 | }
43 |
44 | // Forget3PID implements POST /account/3pid/delete
45 | func Forget3PID() (int, core.Coder) {
46 | return http.StatusOK, nil
47 | }
48 |
--------------------------------------------------------------------------------
/cmd/content/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "github.com/finogeeks/ligase/content"
5 | )
6 |
7 | func main() {
8 | content.Entry()
9 | }
10 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/appService.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "github.com/finogeeks/ligase/appservice"
19 | "github.com/finogeeks/ligase/common"
20 | "github.com/finogeeks/ligase/common/basecomponent"
21 | )
22 |
23 | func StartAppService(base *basecomponent.BaseDendrite, cmd *serverCmdPar) {
24 | transportMultiplexer := common.GetTransportMultiplexer()
25 | kafka := base.Cfg.Kafka
26 |
27 | addConsumer(transportMultiplexer, kafka.Consumer.OutputRoomEventAppservice, base.Cfg.MultiInstance.Instance)
28 |
29 | transportMultiplexer.PreStart()
30 |
31 | appservice.SetupApplicationServiceComponent(base)
32 | }
33 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/persistServer.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "github.com/finogeeks/ligase/cachewriter"
19 | "github.com/finogeeks/ligase/common"
20 | "github.com/finogeeks/ligase/common/basecomponent"
21 | "github.com/finogeeks/ligase/dbupdates"
22 | "github.com/finogeeks/ligase/dbwriter"
23 | )
24 |
25 | func StartPersistServer(base *basecomponent.BaseDendrite, cmd *serverCmdPar) {
26 | transportMultiplexer := common.GetTransportMultiplexer()
27 | kafka := base.Cfg.Kafka
28 |
29 | addConsumer(transportMultiplexer, kafka.Consumer.CacheUpdates, base.Cfg.MultiInstance.Instance)
30 | addConsumer(transportMultiplexer, kafka.Consumer.DBUpdates, base.Cfg.MultiInstance.Instance)
31 |
32 | transportMultiplexer.PreStart()
33 |
34 | cachewriter.SetupCacheWriterComponent(base)
35 | dbwriter.SetupDBWriterComponent(base)
36 |
37 | dbupdates.SetupDBUpdateComponent(base.Cfg)
38 | dbupdates.SetupCacheUpdateComponent(base.Cfg)
39 | }
40 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/pushSender.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "github.com/finogeeks/ligase/common"
19 | "github.com/finogeeks/ligase/common/basecomponent"
20 | "github.com/finogeeks/ligase/common/uid"
21 | "github.com/finogeeks/ligase/pushsender"
22 | )
23 |
24 | func StartPushSender(base *basecomponent.BaseDendrite, cmd *serverCmdPar) {
25 | transportMultiplexer := common.GetTransportMultiplexer()
26 | kafka := base.Cfg.Kafka
27 |
28 | addProducer(transportMultiplexer, kafka.Producer.DBUpdates)
29 |
30 | for _, v := range dbUpdateProducerName {
31 | dbUpdates := kafka.Producer.DBUpdates
32 | dbUpdates.Topic = dbUpdates.Topic + "_" + v
33 | dbUpdates.Name = dbUpdates.Name + "_" + v
34 | addProducer(transportMultiplexer, dbUpdates)
35 | }
36 |
37 | transportMultiplexer.PreStart()
38 |
39 | idg, _ := uid.NewDefaultIdGenerator(base.Cfg.Matrix.InstanceId)
40 | rpcClient := common.NewRpcClient(base.Cfg.Nats.Uri, idg)
41 | rpcClient.Start(false)
42 |
43 | pushsender.SetupPushSenderComponent(base, rpcClient)
44 | }
45 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/redirectStderr_darwin.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "log"
19 | "os"
20 | "syscall"
21 | )
22 |
23 | func initPanicFile(file string) {
24 | errFile, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
25 | if err != nil {
26 | log.Fatalf("Failed to open log file:%v", err)
27 | }
28 |
29 | if err = syscall.Dup2(int(errFile.Fd()), int(os.Stderr.Fd())); err != nil {
30 | log.Fatalf("Failed to dup stderr:%v", err)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/redirectStderr_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "log"
19 | "os"
20 | "syscall"
21 | )
22 |
23 | func initPanicFile(file string) {
24 | errFile, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
25 | if err != nil {
26 | log.Fatalf("Failed to open log file:%v", err)
27 | }
28 |
29 | if err = syscall.Dup2(int(errFile.Fd()), int(os.Stderr.Fd())); err != nil {
30 | log.Fatalf("Failed to dup stderr:%v", err)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/redirectStderr_windows.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "log"
19 | "os"
20 | "syscall"
21 | )
22 |
23 | func initPanicFile(file string) {
24 | errFile, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
25 | if err != nil {
26 | log.Fatalf("Failed to open log file:%v", err)
27 | }
28 |
29 | kernel32 := syscall.NewLazyDLL("kernel32.dll")
30 | setStdHandle := kernel32.NewProc("SetStdHandle")
31 | sh := syscall.STD_ERROR_HANDLE
32 | v, _, err := setStdHandle.Call(uintptr(sh), uintptr(errFile.Fd()))
33 | if v == 0 {
34 | log.Fatalf("Failed to dup stderr:%v", err)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/syncWriter.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "github.com/finogeeks/ligase/common"
19 | "github.com/finogeeks/ligase/common/basecomponent"
20 | "github.com/finogeeks/ligase/syncwriter"
21 | )
22 |
23 | func StartSyncWriter(base *basecomponent.BaseDendrite, cmd *serverCmdPar) {
24 | transportMultiplexer := common.GetTransportMultiplexer()
25 | kafka := base.Cfg.Kafka
26 |
27 | addProducer(transportMultiplexer, kafka.Producer.DBUpdates)
28 |
29 | for _, v := range dbUpdateProducerName {
30 | dbUpdates := kafka.Producer.DBUpdates
31 | dbUpdates.Topic = dbUpdates.Topic + "_" + v
32 | dbUpdates.Name = dbUpdates.Name + "_" + v
33 | addProducer(transportMultiplexer, dbUpdates)
34 | }
35 |
36 | addConsumer(transportMultiplexer, kafka.Consumer.OutputRoomEventSyncWriter, base.Cfg.MultiInstance.Instance)
37 |
38 | transportMultiplexer.PreStart()
39 |
40 | syncwriter.SetupSyncWriterComponent(base)
41 | }
42 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/tokenRewrite.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | import (
18 | "github.com/finogeeks/ligase/common"
19 | "github.com/finogeeks/ligase/common/basecomponent"
20 | "github.com/finogeeks/ligase/common/uid"
21 | "github.com/finogeeks/ligase/tokenrewrite"
22 | )
23 |
24 | func StartTokenRewrite(base *basecomponent.BaseDendrite, cmd *serverCmdPar) {
25 | idg, _ := uid.NewDefaultIdGenerator(base.Cfg.Matrix.InstanceId)
26 | rpcClient := common.NewRpcClient(base.Cfg.Nats.Uri, idg)
27 | rpcClient.Start(true)
28 | tokenrewrite.SetupTokenRewrite(rpcClient, base.Cfg)
29 | }
30 |
--------------------------------------------------------------------------------
/cmd/engine-server/entry/version.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package entry
16 |
17 | const (
18 | VERSION = "4.9.4-120-gcf21346e3"
19 | BUILD = "2020-04-26T15:52:43+0800"
20 | )
21 |
--------------------------------------------------------------------------------
/cmd/engine-server/main.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package main
16 |
17 | import (
18 | "github.com/finogeeks/ligase/cmd/engine-server/entry"
19 | )
20 |
21 | func main() {
22 | entry.Entry()
23 | }
24 |
--------------------------------------------------------------------------------
/cmd/federation/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "github.com/finogeeks/ligase/federation"
5 | )
6 |
7 | func main() {
8 | federation.Entry()
9 | }
10 |
--------------------------------------------------------------------------------
/cmd/stress/invite.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package main
16 |
17 | import (
18 | "bytes"
19 | "encoding/json"
20 | "net/http"
21 | "strconv"
22 | )
23 |
24 | type inviteRequest struct {
25 | UserID string `json:"user_id"`
26 | AutoJoin bool `json:"auto_join"`
27 | }
28 |
29 | func buildInviteURL(roomID, token, host string, port int) string {
30 | return "http://" + host + ":" + strconv.Itoa(port) + "/_matrix/client/r0/rooms/" + roomID + "/invite?access_token=" + token
31 | }
32 |
33 | func doInvite(seed int, url string, autoJoin bool) (*http.Response, error) {
34 | var crReq inviteRequest
35 | crReq.UserID = "test" + strconv.Itoa(seed) + ":" + *domain
36 | crReq.AutoJoin = autoJoin
37 |
38 | content, _ := json.Marshal(crReq)
39 |
40 | req, _ := http.NewRequest("POST", url, bytes.NewBuffer(content))
41 | req.Header.Add("Content-Type", "application/json")
42 | req.Header.Add("cache-control", "no-cache")
43 |
44 | return http.DefaultClient.Do(req)
45 | }
46 |
--------------------------------------------------------------------------------
/common/code.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package common
16 |
17 | import (
18 | "encoding/base64"
19 | )
20 |
21 | func ToBase64(b []byte) string {
22 | return base64.StdEncoding.EncodeToString(b)
23 | }
24 |
25 | func FromBase64(in string) []byte {
26 | out := make([]byte, base64.StdEncoding.DecodedLen(len(in)))
27 | n, err := base64.StdEncoding.Decode(out, []byte(in))
28 | if err != nil {
29 | panic("failed to base64 decode")
30 | }
31 | return out[:n]
32 | }
33 |
--------------------------------------------------------------------------------
/common/filter/IFilterLoad.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package filter
16 |
17 | import "context"
18 |
19 | type FilterLoader interface {
20 | LoadFilterData(context.Context, string, *Filter) bool
21 | }
22 |
23 | type SimpleFilterLoader interface {
24 | LoadSimpleFilterData(context.Context, *SimpleFilter) bool
25 | }
26 |
--------------------------------------------------------------------------------
/common/jsonerror/jsonerror_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package jsonerror
19 |
20 | import (
21 | "encoding/json"
22 | "testing"
23 | )
24 |
25 | func TestLimitExceeded(t *testing.T) {
26 | e := LimitExceeded("too fast", 5000)
27 | jsonBytes, err := json.Marshal(&e)
28 | if err != nil {
29 | t.Fatalf("TestLimitExceeded: Failed to marshal LimitExceeded error. %s", err.Error())
30 | }
31 | want := `{"errcode":"M_LIMIT_EXCEEDED","error":"too fast","retry_after_ms":5000}`
32 | if string(jsonBytes) != want {
33 | t.Errorf("TestLimitExceeded: want %s, got %s", want, string(jsonBytes))
34 | }
35 | }
36 |
37 | func TestForbidden(t *testing.T) {
38 | e := Forbidden("you shall not pass")
39 | jsonBytes, err := json.Marshal(&e)
40 | if err != nil {
41 | t.Fatalf("TestForbidden: Failed to marshal Forbidden error. %s", err.Error())
42 | }
43 | want := `{"errcode":"M_FORBIDDEN","error":"you shall not pass"}`
44 | if string(jsonBytes) != want {
45 | t.Errorf("TestForbidden: want %s, got %s", want, string(jsonBytes))
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/common/keydb/keyring.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 New Vector Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package keydb
19 |
20 | import "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
21 |
22 | // CreateKeyRing creates and configures a KeyRing object.
23 | //
24 | // It creates the necessary key fetchers and collects them into a KeyRing
25 | // backed by the given KeyDatabase.
26 | func CreateKeyRing(client gomatrixserverlib.Client,
27 | keyDB gomatrixserverlib.KeyDatabase) gomatrixserverlib.KeyRing {
28 | return gomatrixserverlib.KeyRing{
29 | KeyFetchers: []gomatrixserverlib.KeyFetcher{
30 | // TODO: Use perspective key fetchers for production.
31 | &gomatrixserverlib.DirectKeyFetcher{Client: client},
32 | },
33 | KeyDatabase: keyDB,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/common/transportMng.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package common
16 |
17 | import (
18 | "sync"
19 |
20 | "github.com/finogeeks/ligase/core"
21 | )
22 |
23 | type MultiplexerMng struct {
24 | transport core.IMultiplexer
25 | processor core.IMultiplexer
26 | }
27 |
28 | var MultiplexerMngInsance *MultiplexerMng
29 | var onceTransportMng sync.Once
30 |
31 | func getMultiplexerMngInstance() *MultiplexerMng {
32 | onceTransportMng.Do(func() {
33 | MultiplexerMngInsance = new(MultiplexerMng)
34 | })
35 |
36 | return MultiplexerMngInsance
37 | }
38 |
39 | func SetTransportMultiplexer(multp core.IMultiplexer) {
40 | instance := getMultiplexerMngInstance()
41 | instance.transport = multp
42 | }
43 |
44 | func SetProcessorMultiplexer(multp core.IMultiplexer) {
45 | instance := getMultiplexerMngInstance()
46 | instance.processor = multp
47 | }
48 |
49 | func GetTransportMultiplexer() core.IMultiplexer {
50 | instance := getMultiplexerMngInstance()
51 | return instance.transport
52 | }
53 |
54 | func GetProcessorMultiplexer() core.IMultiplexer {
55 | instance := getMultiplexerMngInstance()
56 | return instance.processor
57 | }
58 |
--------------------------------------------------------------------------------
/common/uid/uidGeneratorMng.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package uid
16 |
17 | import (
18 | "sync"
19 |
20 | log "github.com/finogeeks/ligase/skunkworks/log"
21 | )
22 |
23 | var once sync.Once
24 | var instance *UidGeneratorMng
25 |
26 | type UidGeneratorMng struct {
27 | generators sync.Map
28 | lock sync.Mutex
29 | }
30 |
31 | func GetUidGeneratorMng() *UidGeneratorMng {
32 | once.Do(func() {
33 | instance = new(UidGeneratorMng)
34 | })
35 |
36 | return instance
37 | }
38 |
39 | func (m *UidGeneratorMng) Register(key string, start, end int64) {
40 | m.lock.Lock()
41 | defer m.lock.Unlock()
42 | _, ok := m.generators.Load(key)
43 | if !ok {
44 | idg, _ := NewIdGenerator(start, end)
45 | m.generators.Store(key, idg)
46 | } else {
47 | log.Errorf("UidGeneratorMng Register conflict key:%s", key)
48 | }
49 | }
50 |
51 | func (m *UidGeneratorMng) GetIdg(key string) *UidGenerator {
52 | val, ok := m.generators.Load(key)
53 | if ok {
54 | return val.(*UidGenerator)
55 | }
56 |
57 | return nil
58 | }
59 |
--------------------------------------------------------------------------------
/config/as-registration.yaml:
--------------------------------------------------------------------------------
1 | # (Optional) Specify this file in config.yaml if you have application service
2 | id: ""
3 | url: ""
4 | as_token: ""
5 | hs_token: ""
6 | sender_localpart:
7 | namespaces:
8 |
9 | users: []
10 |
11 |
12 |
13 | aliases: []
14 |
15 |
16 |
17 | rooms: []
--------------------------------------------------------------------------------
/content/storage/implements/init.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package implements
16 |
17 | import (
18 | _ "github.com/finogeeks/ligase/content/storage/implements/content"
19 | )
20 |
--------------------------------------------------------------------------------
/content/storage/model/contentDB.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import "context"
18 |
19 | type MediaDownloadInfo struct {
20 | RoomID string
21 | EventID string
22 | Event string
23 | }
24 |
25 | type ContentDatabase interface {
26 | InsertMediaDownload(ctx context.Context, roomID, eventID, event string) error
27 | UpdateMediaDownload(ctx context.Context, roomID, eventID string, finished bool) error
28 | SelectMediaDownload(ctx context.Context) (roomIDs, eventIDs, events []string, err error)
29 | }
30 |
--------------------------------------------------------------------------------
/content/version.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package content
16 |
17 | const (
18 | VERSION = "3.4.3-127-ga8a8c67c"
19 | BUILD = "2019-12-26T16:04:56+0800"
20 | )
21 |
--------------------------------------------------------------------------------
/core/IConfig.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package core
16 |
17 | type IConfig interface {
18 | GetDBConfig(name string) (driver string, createAddr string, addr string, persistUnderlying string, persistName string, async bool)
19 | }
20 |
--------------------------------------------------------------------------------
/core/IMessage.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package core
16 |
17 | type InputMsg interface {
18 | InitFromBytes([]byte)
19 | GetMsgType() int32
20 | }
21 |
22 | type Coder interface {
23 | Encode() ([]byte, error)
24 | Decode(input []byte) error
25 | }
26 |
27 | const (
28 | FORMAT_JSON = int8(0)
29 | FORMAT_GOB = int8(1)
30 | FORMAT_CAPN = int8(2)
31 | )
32 |
--------------------------------------------------------------------------------
/dbupdates/dbregistry/dbregistry.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package dbregistry
16 |
17 | import (
18 | "sync"
19 |
20 | "github.com/finogeeks/ligase/dbupdates/dbupdatetypes"
21 | "github.com/finogeeks/ligase/skunkworks/log"
22 | )
23 |
24 | type DBRegistry struct {
25 | Persist dbupdatetypes.ProcessorFactory
26 | Cache dbupdatetypes.CacheFactory
27 | }
28 |
29 | var (
30 | registry sync.Map
31 | )
32 |
33 | func Register(key string, persist dbupdatetypes.ProcessorFactory, cache dbupdatetypes.CacheFactory) {
34 | if persist == nil && cache == nil {
35 | return
36 | }
37 | _, loaded := registry.LoadOrStore(key, DBRegistry{Persist: persist, Cache: cache})
38 | if loaded {
39 | log.Errorf("dbupdates registry already exists %s", key)
40 | }
41 | }
42 |
43 | func GetAllKeys() []string {
44 | keys := []string{}
45 | registry.Range(func(k, v interface{}) bool {
46 | keys = append(keys, k.(string))
47 | return true
48 | })
49 | return keys
50 | }
51 |
52 | func GetRegistryProc(key string) (DBRegistry, bool) {
53 | v, ok := registry.Load(key)
54 | if !ok {
55 | return DBRegistry{}, false
56 | }
57 | return v.(DBRegistry), true
58 | }
59 |
--------------------------------------------------------------------------------
/dbupdates/dbupdates.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package dbupdates
16 |
17 | import (
18 | "github.com/finogeeks/ligase/common/config"
19 | "github.com/finogeeks/ligase/dbupdates/consumers"
20 | _ "github.com/finogeeks/ligase/dbupdates/processors"
21 | "github.com/finogeeks/ligase/skunkworks/log"
22 | )
23 |
24 | func SetupDBUpdateComponent(cfg *config.Dendrite) {
25 | manager := consumers.NewDBEventSeqManager(cfg)
26 | if err := manager.Start(); err != nil {
27 | log.Errorf("DBEventSeqManager Start err %v", err)
28 | }
29 | }
30 |
31 | func SetupCacheUpdateComponent(cfg *config.Dendrite) {
32 | manager := consumers.NewCacheUpdateManager(cfg)
33 | if err := manager.Start(); err != nil {
34 | log.Errorf("CacheUpdateManager Start err %v", err)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/dbupdates/dbupdatetypes/types.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package dbupdatetypes
16 |
17 | import (
18 | "context"
19 |
20 | "github.com/finogeeks/ligase/common/config"
21 | "github.com/finogeeks/ligase/model/dbtypes"
22 | "github.com/gomodule/redigo/redis"
23 | )
24 |
25 | type DBEventDataInput struct {
26 | Data []byte
27 | RawMsg interface{}
28 | Event *dbtypes.DBEvent
29 | }
30 |
31 | type CacheInput struct {
32 | Event *dbtypes.DBEvent
33 | }
34 |
35 | type DBEventSeqProcessor interface {
36 | Start()
37 | Process(ctx context.Context, input []DBEventDataInput) error
38 | }
39 |
40 | type KafkaCommiter interface {
41 | Commit(rawMsg []interface{}) error
42 | }
43 |
44 | type DBEventSeqBatch interface {
45 | BatchKeys() map[int64]bool
46 | }
47 |
48 | type CacheProcessor interface {
49 | Start()
50 | Process(ctx context.Context, input CacheInput) error
51 | }
52 |
53 | type Pool interface {
54 | Pool() *redis.Pool
55 | }
56 |
57 | type ProcessorFactory = func(string, *config.Dendrite) DBEventSeqProcessor
58 | type CacheFactory = func(string, *config.Dendrite, Pool) CacheProcessor
59 |
--------------------------------------------------------------------------------
/dbupdates/processors/init.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package init
16 |
17 | import (
18 | _ "github.com/finogeeks/ligase/dbupdates/processors/account"
19 | _ "github.com/finogeeks/ligase/dbupdates/processors/device"
20 | _ "github.com/finogeeks/ligase/dbupdates/processors/encryptapi"
21 | _ "github.com/finogeeks/ligase/dbupdates/processors/presence"
22 | _ "github.com/finogeeks/ligase/dbupdates/processors/publicroomsapi"
23 | _ "github.com/finogeeks/ligase/dbupdates/processors/pushapi"
24 | _ "github.com/finogeeks/ligase/dbupdates/processors/roomserver"
25 | _ "github.com/finogeeks/ligase/dbupdates/processors/syncapi"
26 | )
27 |
--------------------------------------------------------------------------------
/dbwriter/consumers/consumer_interface.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package consumers
16 |
17 | import (
18 | "context"
19 | "sync"
20 |
21 | "github.com/finogeeks/ligase/common/config"
22 | "github.com/finogeeks/ligase/model/dbtypes"
23 | log "github.com/finogeeks/ligase/skunkworks/log"
24 | "github.com/finogeeks/ligase/skunkworks/monitor/go-client/monitor"
25 | )
26 |
27 | var regMu sync.RWMutex
28 | var newHandler = make(map[int64]func() ConsumerInterface)
29 |
30 | type ConsumerInterface interface {
31 | OnMessage(context.Context, *dbtypes.DBEvent) error
32 | Prepare(*config.Dendrite)
33 | Report(monitor.LabeledGauge)
34 | Start()
35 | }
36 |
37 | func Register(name int64, f func() ConsumerInterface) {
38 | regMu.Lock()
39 | defer regMu.Unlock()
40 |
41 | if f == nil {
42 | log.Panicf("Register: %s func nil", dbtypes.DBCategoryToStr(name))
43 | }
44 |
45 | if _, ok := newHandler[name]; ok {
46 | log.Panicf("Register: %s already registered", dbtypes.DBCategoryToStr(name))
47 | }
48 |
49 | newHandler[name] = f
50 | }
51 |
--------------------------------------------------------------------------------
/dbwriter/dbwriter.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package dbwriter
19 |
20 | import (
21 | "github.com/finogeeks/ligase/common/basecomponent"
22 | "github.com/finogeeks/ligase/dbwriter/consumers"
23 |
24 | "github.com/finogeeks/ligase/skunkworks/log"
25 | )
26 |
27 | func SetupDBWriterComponent(
28 | base *basecomponent.BaseDendrite,
29 | ) {
30 | dbEvConsumer := consumers.NewDBEventDataConsumer(base.Cfg)
31 |
32 | if err := dbEvConsumer.Start(); err != nil {
33 | log.Panicw("failed to start dbwriter consumer", log.KeysAndValues{"error", err})
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '2'
2 | services:
3 | zookeeper:
4 | hostname: zookeeper
5 | image: 'zookeeper'
6 | kafka:
7 | image: 'wurstmeister/kafka'
8 | ports:
9 | - 9092:9092
10 | environment:
11 | KAFKA_ADVERTISED_HOST_NAME: kafka
12 | KAFKA_ADVERTISED_PORT: 9092
13 | KAFKA_DELETE_TOPIC_ENABLE: "true"
14 | KAFKA_AUTO_CREATE_TOPICS: "true"
15 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
16 | KAFKA_LISTENERS: PLAINTEXT://:9092
17 | KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
18 | KAFKA_LOG_RETENTION_HOURS: 24
19 | depends_on:
20 | - zookeeper
21 | links:
22 | - 'zookeeper'
23 | redis:
24 | image: 'redis'
25 | ports:
26 | - 6379:6379
27 | pg-master:
28 | image: 'postgres'
29 | environment:
30 | POSTGRES_USER: 'postgres'
31 | POSTGRES_PASSWORD: 'postgres'
32 | POSTGRES_DB: 'postgres'
33 | PGDATA: '/var/lib/postgresql/data'
34 | REDIS_SERVER: 'redis'
35 | depends_on:
36 | - redis
37 | ports:
38 | - 5432:5432
39 | links:
40 | - 'redis'
41 | nats:
42 | image: 'apcera/gnatsd'
43 | environment:
44 | MAX_PAYLOAD: 33554432
45 | ports:
46 | - 4222:4222
47 |
--------------------------------------------------------------------------------
/docs/dev/git/contribution_dev_process.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/docs/dev/git/contribution_dev_process.jpg
--------------------------------------------------------------------------------
/docs/dev/git/git.md:
--------------------------------------------------------------------------------
1 | # 注意事项
2 |
3 | 这里列举的注意事项主要是为了能让Ligase的git log保持干净,也就是所谓的保持线性。比如运行`git log --graph`,能得到如下的结果
4 |
5 |
6 |
7 | 为了达到这个结果,我们使用[`Rebasing/Cherry-Picking Workflow`](https://git-scm.com/book/en/v2/Distributed-Git-Maintaining-a-Project)来管理Ligase,需要在开发和发布中注意如下的事项
8 |
9 | ## 开发中的注意实现
10 |
11 | 开发的流程图如下,其中特别值得注意的是
12 |
13 | * 在push代码之前,一定要`git rebase upstream/develop`
14 | * 在合并PR的时候,**一定要使用`squash and merge`**
15 |
16 |
17 |
18 | 由于我们使用`git rebase`来合并commit,因此在连续提交的时候(合并PR之后继续在同一分支开发,或者若干个PR前后依赖)会很容易碰到冲突,或者造成commit message混乱。解决办法如下:
19 |
20 | * 不要提交前后依赖的PR
21 | * 每次合并PR之后,新建分支进行新的开发
22 |
23 |
24 |
25 | ## 发布时的注意事项
26 |
27 | 由于Github的rebase行为与git的不同,[前者会生成新的sha](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#rebase-and-merge-your-pull-request-commits)。因此,针对master和release分支,我们使用命令行来合并commit,而**不使用Github的PR!!!**
28 |
29 | ### 发布流程
30 |
31 | Ligase的发布流程与`git flow`比较类似:
32 |
33 | * 下图中,从上到下,分支的稳定性依次降低。比如master的稳定性比release_xxx更高
34 | * 原则上master分支不走开发流程
35 | * 当多个分支需要做同样的修改时,比如bug fix(下图中的6):
36 | * 从稳定性更高的分支(master除外)开始,走开发流程修复bug,比如下图的release
37 | * 代码开发并合并之后,从当前分支向其他分支同步修改(使用`git rebase或者git cherry-pick`)
38 |
39 |
40 |
41 | ## 总结
42 |
43 | 将上文总结一下,有三个点需要特别注意:
44 |
45 | * 做开发点分支(PR分支)用完就扔
46 | * 使用`squash and merge`来合并PR
47 | * 使用命令行来管理master和release_xxx分支
48 |
49 |
--------------------------------------------------------------------------------
/docs/dev/git/git_clean.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/docs/dev/git/git_clean.jpg
--------------------------------------------------------------------------------
/docs/dev/git/ligase_dev_circle.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/docs/dev/git/ligase_dev_circle.jpg
--------------------------------------------------------------------------------
/docs/dev/git/ligase_dev_notes.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/docs/dev/git/ligase_dev_notes.jpg
--------------------------------------------------------------------------------
/docs/dev/git/ligase_dev_release_notes.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/docs/dev/git/ligase_dev_release_notes.jpg
--------------------------------------------------------------------------------
/docs/dev/git/ligase_release_proc.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/docs/dev/git/ligase_release_proc.jpg
--------------------------------------------------------------------------------
/federation/.gitignore:
--------------------------------------------------------------------------------
1 | /federation
2 |
--------------------------------------------------------------------------------
/federation/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM docker.finogeeks.club/finochat/dendrite_build
2 | #FROM golang
3 |
4 | RUN mkdir -p /mnt/data/logs
5 | ENV LOG_DIR=/mnt/data/logs
6 |
7 | COPY dockerize /usr/bin
8 |
9 | ADD ./config /opt/federation/config
10 | ADD ./federation /opt/federation/federation
11 | ADD ./run.sh /opt/federation/run.sh
12 |
13 | WORKDIR /opt/federation
14 | #CMD ./federation
15 | CMD ./run.sh $RUN_ENV
16 |
--------------------------------------------------------------------------------
/federation/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 | Copyright (c)
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
--------------------------------------------------------------------------------
/federation/README.md:
--------------------------------------------------------------------------------
1 | [](https://drone.finogeeks.club/skunkworks/federation)
2 | # federation
3 |
4 | im homeserver federation service
--------------------------------------------------------------------------------
/federation/build.sh:
--------------------------------------------------------------------------------
1 | export GO111MODULE=on
2 | #export GOPROXY=https://goproxy.io
3 | export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
4 |
5 | echo "fmt"
6 | gofmt -s -w .
7 |
8 | go mod tidy
9 | go build
10 |
--------------------------------------------------------------------------------
/federation/docker-compose.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/federation/docker-compose.yml
--------------------------------------------------------------------------------
/federation/fedsync/syncconsumer/invite.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package syncconsumer
16 |
17 | import (
18 | "context"
19 |
20 | "github.com/finogeeks/ligase/federation/client"
21 | "github.com/finogeeks/ligase/model/service/roomserverapi"
22 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
23 | log "github.com/finogeeks/ligase/skunkworks/log"
24 | )
25 |
26 | func SendInvite(
27 | ctx context.Context,
28 | fedClient *client.FedClientWrap,
29 | request *roomserverapi.FederationEvent,
30 | destination string,
31 | ) gomatrixserverlib.RespInvite {
32 | var event gomatrixserverlib.Event
33 | if err := json.Unmarshal(request.Extra, &event); err != nil {
34 | log.Errorf("federation Download unmarshal error: %v", err)
35 | return gomatrixserverlib.RespInvite{Code: 400}
36 | }
37 |
38 | fedResp, err := fedClient.SendInvite(ctx, destination, event)
39 | if err != nil {
40 | log.Errorf("federation SendInvite error %v", err)
41 | }
42 | return fedResp
43 | }
44 |
--------------------------------------------------------------------------------
/federation/model/backfilltypes/backfillProc.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package backfilltypes
16 |
17 | import (
18 | "context"
19 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
20 | )
21 |
22 | type BackFillProcessor interface {
23 | AddRequest(ctx context.Context, evs []gomatrixserverlib.Event, limit bool) error
24 | }
25 |
--------------------------------------------------------------------------------
/federation/run-fed1.sh:
--------------------------------------------------------------------------------
1 | if [ "$USER" == "joey" ]; then
2 | #export RUN_ENV="fed1"
3 | sh ./config/env.sh "fed1"
4 | ./federation
5 | fi
6 |
--------------------------------------------------------------------------------
/federation/run-fed2.sh:
--------------------------------------------------------------------------------
1 | if [ "$USER" == "joey" ]; then
2 | #export RUN_ENV="fed2"
3 | sh ./config/env.sh "fed2"
4 | ./federation
5 | fi
6 |
--------------------------------------------------------------------------------
/federation/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | base=`pwd`
4 |
5 | sh ./config/env.sh $1
6 | cat ./config/fed.yaml
7 |
8 | ./federation
9 |
--------------------------------------------------------------------------------
/federation/storage/implements/init.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package implements
16 |
17 | import (
18 | _ "github.com/finogeeks/ligase/federation/storage/implements/federation"
19 | )
20 |
--------------------------------------------------------------------------------
/federation/version.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package federation
16 |
17 | const (
18 | VERSION = "4.9.4-120-gcf21346e3"
19 | BUILD = "2020-04-26T15:52:43+0800"
20 | )
21 |
--------------------------------------------------------------------------------
/logo/ligase_100_320.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/logo/ligase_100_320.png
--------------------------------------------------------------------------------
/logo/ligase_100_320a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/logo/ligase_100_320a.png
--------------------------------------------------------------------------------
/logo/ligase_480_480.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/logo/ligase_480_480.png
--------------------------------------------------------------------------------
/logo/ligase_480_480a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/logo/ligase_480_480a.png
--------------------------------------------------------------------------------
/model/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 | Copyright (c)
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
--------------------------------------------------------------------------------
/model/README.md:
--------------------------------------------------------------------------------
1 | # message
2 |
3 | 内部消息结构
--------------------------------------------------------------------------------
/model/authtypes/account.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package authtypes
19 |
20 | import (
21 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
22 | )
23 |
24 | // Account represents a Matrix account on this home server.
25 | type Account struct {
26 | UserID string
27 | ServerName gomatrixserverlib.ServerName
28 | Profile *Profile
29 | AppServiceID string
30 | // TODO: Other flags like IsAdmin, IsGuest
31 | // TODO: Devices
32 | // TODO: Associations (e.g. with application services)
33 | }
34 |
35 | type RoomTagCacheData struct {
36 | UserID string
37 | RoomID string
38 | Tag string
39 | Content string
40 | }
41 |
42 | type AccountDataCacheData struct {
43 | UserID string
44 | Type string
45 | Content string
46 | }
47 |
48 | type RoomAccountDataCacheData struct {
49 | UserID string
50 | RoomID string
51 | Type string
52 | Content string
53 | }
54 |
55 | type RoomTags struct {
56 | Tags map[string]interface{} `json:"tags"`
57 | }
58 |
--------------------------------------------------------------------------------
/model/authtypes/device.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package authtypes
19 |
20 | // Device represents a client's device (mobile, web, etc)
21 | type Device struct {
22 | ID string `json:"id,omitempty"`
23 | UserID string `json:"user_id,omitempty"`
24 | DisplayName string `json:"display_name,omitempty"`
25 | DeviceType string `json:"device_type,omitempty"`
26 | IsHuman bool `json:"is_human,omitempty"`
27 | Identifier string `json:"identifier,omitempty"`
28 | CreateTs int64 `json:"create_ts,omitempty"`
29 | LastActiveTs int64 `json:"last_active_ts,omitempty"`
30 | }
31 |
--------------------------------------------------------------------------------
/model/authtypes/logintypes.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package authtypes
19 |
20 | // The relevant login types implemented in Ligase
21 | const (
22 | LoginTypeDummy = "m.login.dummy"
23 | LoginTypeSharedSecret = "org.matrix.login.shared_secret"
24 | LoginTypeRecaptcha = "m.login.recaptcha"
25 | LoginTypePassword = "m.login.password"
26 |
27 | LoginTypeApplicationService = "m.login.application_service"
28 | )
29 |
--------------------------------------------------------------------------------
/model/authtypes/presence.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package authtypes
16 |
17 | type Presences struct {
18 | UserID string
19 | Status string
20 | StatusMsg string
21 | ExtStatusMsg string
22 | ServerStatus string
23 | }
24 |
--------------------------------------------------------------------------------
/model/authtypes/profile.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package authtypes
19 |
20 | // Profile represents the profile for a Matrix account on this home server.
21 | type Profile struct {
22 | UserID string
23 | DisplayName string
24 | AvatarURL string
25 | }
26 |
27 | // UserInfo represents the user information for a Matrix account on this home server.
28 | type UserInfo struct {
29 | UserID string
30 | UserName string
31 | JobNumber string
32 | Mobile string
33 | Landline string
34 | Email string
35 | State int
36 | }
37 |
--------------------------------------------------------------------------------
/model/dbtypes/presence_dbev.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package dbtypes
16 |
17 | const (
18 | PresencesInsertKey int64 = 0
19 | PresenceMaxKey int64 = 1
20 | )
21 |
22 | func PresenceDBEventKeyToStr(key int64) string {
23 | switch key {
24 | case PresencesInsertKey:
25 | return "PresencesInsert"
26 | default:
27 | return "unknown"
28 | }
29 | }
30 |
31 | func PresenceDBEventKeyToTableStr(key int64) string {
32 | switch key {
33 | case PresencesInsertKey:
34 | return "presence_presences"
35 | default:
36 | return "unknown"
37 | }
38 | }
39 |
40 | type PresenceDBEvent struct {
41 | PresencesInsert *PresencesInsert `json:"presences_insert,omitempty"`
42 | }
43 |
44 | type PresencesInsert struct {
45 | UserID string `json:"user_id"`
46 | Status string `json:"status"`
47 | StatusMsg string `json:"status_msg"`
48 | ExtStatusMsg string `json:"ext_status_msg"`
49 | }
50 |
--------------------------------------------------------------------------------
/model/error.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | "errors"
19 | )
20 |
21 | var (
22 | ErrConnClosed = errors.New("connection was closed")
23 | ErrRequestTimedOut = errors.New("request timed out")
24 | ErrUnknown = errors.New("unknown error")
25 | )
26 |
27 | type ErrStr struct {
28 | s string
29 | }
30 |
31 | func (str ErrStr) error() error {
32 | return errors.New(str.s)
33 | }
34 |
--------------------------------------------------------------------------------
/model/feedstypes/Ifeed.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | type Feed interface {
18 | GetOffset() int64
19 | }
20 |
--------------------------------------------------------------------------------
/model/feedstypes/clientDataStream.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/types"
19 | )
20 |
21 | type ClientDataStream struct {
22 | Offset int64
23 | DataStream *types.ActDataStreamUpdate
24 | }
25 |
26 | func (cds *ClientDataStream) GetOffset() int64 {
27 | return cds.Offset
28 | }
29 |
30 | func (cds *ClientDataStream) GetDataStream() *types.ActDataStreamUpdate {
31 | return cds.DataStream
32 | }
33 |
--------------------------------------------------------------------------------
/model/feedstypes/eventReadStream.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | type EventReadStream struct {
18 | Offset int64
19 | EventID string
20 | EventType string
21 | }
22 |
23 | func (es *EventReadStream) GetOffset() int64 {
24 | return es.Offset
25 | }
26 |
--------------------------------------------------------------------------------
/model/feedstypes/keyChangeStream.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/types"
19 | )
20 |
21 | type KeyChangeStream struct {
22 | Offset int64
23 | DataStream *types.KeyChangeStream
24 | }
25 |
26 | func (kcs *KeyChangeStream) GetOffset() int64 {
27 | return kcs.Offset
28 | }
29 |
30 | func (kcs *KeyChangeStream) GetDataStream() *types.KeyChangeStream {
31 | return kcs.DataStream
32 | }
33 |
--------------------------------------------------------------------------------
/model/feedstypes/presenceDataStream.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/types"
19 | )
20 |
21 | type PresenceDataStream struct {
22 | Offset int64
23 | DataStream *types.PresenceStream
24 | }
25 |
26 | func (pds *PresenceDataStream) GetOffset() int64 {
27 | return pds.Offset
28 | }
29 |
30 | func (pds *PresenceDataStream) GetDataStream() *types.PresenceStream {
31 | return pds.DataStream
32 | }
33 |
--------------------------------------------------------------------------------
/model/feedstypes/receiptDataStream.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/types"
19 | )
20 |
21 | type ReceiptDataStream struct {
22 | Offset int64
23 | DataStream *types.ReceiptStream
24 | Written bool
25 | }
26 |
27 | func (rds *ReceiptDataStream) GetOffset() int64 {
28 | return rds.Offset
29 | }
30 |
31 | func (rds *ReceiptDataStream) GetDataStream() *types.ReceiptStream {
32 | return rds.DataStream
33 | }
34 |
--------------------------------------------------------------------------------
/model/feedstypes/stdEventStream.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/types"
19 | )
20 |
21 | type STDEventStream struct {
22 | Offset int64
23 | DataStream *types.StdEvent
24 | TargetUserID string
25 | TargetDeviceID string
26 | Written bool
27 | Read bool
28 | }
29 |
30 | func (stdEventStream *STDEventStream) GetOffset() int64 {
31 | return stdEventStream.Offset
32 | }
33 |
34 | func (stdEventStream *STDEventStream) GetDataStream() *types.StdEvent {
35 | return stdEventStream.DataStream
36 | }
37 |
--------------------------------------------------------------------------------
/model/feedstypes/streamEvent.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | import (
18 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
19 | )
20 |
21 | type StreamEvent struct {
22 | Offset int64
23 | Ev *gomatrixserverlib.ClientEvent
24 | IsDeleted bool
25 | }
26 |
27 | func (se *StreamEvent) GetOffset() int64 {
28 | return se.Offset
29 | }
30 |
31 | func (se *StreamEvent) GetEv() *gomatrixserverlib.ClientEvent {
32 | return se.Ev
33 | }
34 |
--------------------------------------------------------------------------------
/model/feedstypes/timeLineEvent.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package feedstypes
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/syncapitypes"
19 | )
20 |
21 | type TimeLineEvent struct {
22 | Offset int64
23 | Ev *syncapitypes.UserTimeLineStream
24 | }
25 |
26 | func (se *TimeLineEvent) GetOffset() int64 {
27 | return se.Offset
28 | }
29 |
30 | func (se *TimeLineEvent) GetEv() *syncapitypes.UserTimeLineStream {
31 | return se.Ev
32 | }
33 |
--------------------------------------------------------------------------------
/model/gob_message.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | "context"
19 |
20 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
21 | )
22 |
23 | // transaction request for federation
24 | type TxnReq struct {
25 | // Content gomatrixserverlib.RawJSON
26 | Origin gomatrixserverlib.ServerName
27 | // gomatrixserverlib.Transaction
28 | Context context.Context
29 | }
30 |
31 | type Head struct {
32 | // Err error // gob didn't support enc/dec errors.errorString{}
33 | ErrStr string
34 | // 消息类型,包括请求,响应,推送三种类型
35 | MsgType MsgType
36 | // 消息序号
37 | MsgSeq string
38 | // 消息所属逻辑节点号
39 | NodeId int64
40 | // api类型
41 | ApiType ApiType
42 | // api接口功能号
43 | Cmd Command
44 | }
45 |
46 | // 内部Gob格式消息体
47 | type GobMessage struct {
48 | Head
49 | Key []byte
50 | //Body Payload
51 | Body []byte
52 | }
53 |
--------------------------------------------------------------------------------
/model/model_test.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | "fmt"
19 | "testing"
20 | )
21 |
22 | func Test_GobMsg(t *testing.T) {
23 | gob := GobMessage{}
24 | gob.MsgType = REQUEST
25 | gob.Body = []byte("abc")
26 |
27 | fmt.Println(gob)
28 | gob.Body = []byte("456")
29 | fmt.Println(gob)
30 |
31 | }
32 | func Test_Version(t *testing.T) {
33 | fmt.Println(Version{})
34 | }
35 |
--------------------------------------------------------------------------------
/model/noticetypes/notice.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package noticetypes
16 |
17 | type GetCertsResponse struct {
18 | RootCA string `json:"root_ca,omitempty"`
19 | ServerCert string `json:"cert_pem,omitempty"`
20 | ServerKey string `json:"key_pem,omitempty"`
21 | CRL string `json:"CRL,omitempty"`
22 | // CrlSnapshot map[string][]string `json:"crl_snapshot,omitempty"`
23 | }
24 |
--------------------------------------------------------------------------------
/model/publicroomstypes/types.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package publicroomstypes
19 |
20 | // PublicRoom represents a local public room
21 | type PublicRoom struct {
22 | RoomID string `json:"room_id"`
23 | Aliases []string `json:"aliases,omitempty"`
24 | CanonicalAlias string `json:"canonical_alias,omitempty"`
25 | Name string `json:"name,omitempty"`
26 | Topic string `json:"topic,omitempty"`
27 | AvatarURL string `json:"avatar_url,omitempty"`
28 | NumJoinedMembers int64 `json:"num_joined_members"`
29 | WorldReadable bool `json:"world_readable"`
30 | GuestCanJoin bool `json:"guest_can_join"`
31 | }
32 |
--------------------------------------------------------------------------------
/model/roomservertypes/types.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | // Package types provides the types that are used internally within the roomserver.
19 | package roomservertypes
20 |
21 | // EventTypeNID is a numeric ID for an event type.
22 | type EventTypeNID int64
23 |
24 | // EventStateKeyNID is a numeric ID for an event state_key.
25 | type EventStateKeyNID int64
26 |
27 | // EventNID is a numeric ID for an event.
28 | type EventNID int64
29 |
30 | // RoomNID is a numeric ID for a room.
31 | type RoomNID int64
32 |
33 | type MembershipState int64
34 |
35 | const (
36 | MembershipStateLeaveOrBan MembershipState = 1
37 | MembershipStateInvite MembershipState = 2
38 | MembershipStateJoin MembershipState = 3
39 | MembershipStateBan MembershipState = 4
40 | MembershipStateUnban MembershipState = 5
41 | )
42 |
43 | type TransactionID struct {
44 | DeviceID string `json:"device_id"`
45 | TransactionID string `json:"id"`
46 | IP string `json:"ip"`
47 | }
48 |
49 | type RoomNIDs struct {
50 | RoomID string
51 | RoomNID int64
52 | }
53 |
--------------------------------------------------------------------------------
/model/service/publicroomsapi/query.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package publicroomsapi
16 |
17 | import (
18 | "context"
19 |
20 | "github.com/finogeeks/ligase/model/publicroomstypes"
21 | )
22 |
23 | type QueryPublicRoomsRequest struct {
24 | // Offset int64 `json:"offset"`
25 | Limit int64 `json:"limit"`
26 | Since string `json:"since"`
27 | Filter string `json:"filter"`
28 | }
29 |
30 | type QueryPublicRoomsResponse struct {
31 | Chunk []publicroomstypes.PublicRoom `json:"chunk"`
32 | NextBatch string `json:"next_batch,omitempty"`
33 | PrevBatch string `json:"prev_batch,omitempty"`
34 | Estimate int64 `json:"total_room_count_estimate,omitempty"`
35 | }
36 |
37 | type PublicRoomsRpcRequest struct {
38 | QueryPublicRooms *QueryPublicRoomsRequest `json:"qry_public_rooms,omitempty"`
39 | Reply string
40 | }
41 |
42 | type PublicRoomsQueryAPI interface {
43 | QueryPublicRooms(
44 | ctx context.Context,
45 | request *QueryPublicRoomsRequest,
46 | response *QueryPublicRoomsResponse,
47 | ) error
48 | }
49 |
--------------------------------------------------------------------------------
/model/service/roomserverapi/edu.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package roomserverapi
16 |
17 | import "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
18 |
19 | type EduApi interface {
20 | ProcessReceipt(edu *gomatrixserverlib.EDU)
21 | ProcessTyping(edu *gomatrixserverlib.EDU)
22 | ProcessProfile(edu *gomatrixserverlib.EDU)
23 | }
24 |
--------------------------------------------------------------------------------
/model/service/roomserverapi/rpc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package roomserverapi
19 |
20 | import (
21 | "context"
22 | )
23 |
24 | type RoomserverRPCAPI interface {
25 | RoomserverAliasAPI
26 | RoomserverQueryAPI
27 | EduApi
28 |
29 | InputRoomEvents(context.Context, *RawEvent) (int, error)
30 | }
31 |
--------------------------------------------------------------------------------
/model/types/keys.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package types
16 |
17 | const (
18 | BODYDEVICEKEY = iota
19 | BODYONETIMEKEY
20 | ONETIMEKEYSTRING
21 | ONETIMEKEYOBJECT
22 | )
23 |
--------------------------------------------------------------------------------
/model/types/storage.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package types
19 |
20 | // KeyHolder structure
21 | type KeyHolder struct {
22 | UserID,
23 | DeviceID,
24 | Signature,
25 | KeyAlgorithm,
26 | KeyID,
27 | Key,
28 | KeyType string
29 | }
30 |
31 | // AlHolder structure
32 | type AlHolder struct {
33 | UserID,
34 | DeviceID,
35 | SupportedAlgorithm string
36 | }
37 |
--------------------------------------------------------------------------------
/model/version.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | "net/http"
19 |
20 | "github.com/finogeeks/ligase/skunkworks/gomatrixutil"
21 | "github.com/json-iterator/go"
22 | )
23 |
24 | var json = jsoniter.ConfigCompatibleWithStandardLibrary
25 |
26 | type Version struct {
27 | Server Server `json:"server"`
28 | }
29 |
30 | type Server struct {
31 | Version string `json:"version"`
32 | Name string `json:"name"`
33 | }
34 |
35 | func (v *Version) Encode() ([]byte, error) {
36 | return json.Marshal(v)
37 | }
38 |
39 | func (v *Version) Decode(input []byte) error {
40 | return json.Unmarshal(input, v)
41 | }
42 |
43 | // Version returns the server version
44 | func GetVersionResp() util.JSONResponse {
45 | return util.JSONResponse{Code: http.StatusOK, JSON: GetVersion()}
46 | }
47 |
48 | func GetVersion() *Version {
49 | return &Version{Server{"dev", "Dendrite"}}
50 | }
51 |
--------------------------------------------------------------------------------
/plugins/init.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package plugins
16 |
17 | import (
18 | _ "github.com/finogeeks/ligase/plugins/channel"
19 | _ "github.com/finogeeks/ligase/plugins/multiplexer"
20 | _ "github.com/finogeeks/ligase/plugins/selector"
21 | _ "github.com/finogeeks/ligase/plugins/transport"
22 | )
23 |
--------------------------------------------------------------------------------
/plugins/message/coder.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package message
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/authtypes"
19 | )
20 |
21 | type IDGenerator interface {
22 | Next() (int64, error)
23 | }
24 |
25 | type CodeFillerWithKey interface {
26 | GetKey(device *authtypes.Device, idg IDGenerator) string
27 | }
28 |
--------------------------------------------------------------------------------
/plugins/message/external/README.md:
--------------------------------------------------------------------------------
1 | capn 使用:
2 | 1.根据消息类型编写对应的 capn schema 定义, 比如 login.capn。
3 | 2.根据 capn schema 定义, 比如 login.capn,定义编译生成 go 代码,login.capn.go:
4 | VENDER_PATH 为 dendrite vender 目录。
5 | 本机安装 capnp 程序: brew install capnp。
6 | 编译需要使用 go 插件, 已生成在:export PATH=$PATH:$VENDER_PATH/bin
7 | 编译:capnp compile -I$VENDER_PATH/src/zombiezen.com/go/capnproto2/std -ogo login.capn
8 | 3.使用生成的 go 代码编写 encode 和 decode 过程。
9 |
10 | 编译和调用 go 代码都需要依赖 zombiezen.com/go/capnproto2。
11 | 调用过程不需要依赖本地 capnp 库。
--------------------------------------------------------------------------------
/plugins/message/external/accountAdmin.capn:
--------------------------------------------------------------------------------
1 | @0xf54464a6078c8b5c;
2 | using Go = import "/go.capnp";
3 | $Go.package("external");
4 | $Go.import("github.com/finogeeks/ligase/plugins/message/external");
5 |
6 | struct GetAccount3PIDResponseCapn {
7 | threePIDs @0: ThirdPartyIdentifierCapn;
8 | }
9 |
10 | struct GetAccountWhoAmIRquestCapn {
11 | userID @0: Text;
12 | }
13 |
14 | struct PostAccount3PIDDelRequestCapn {
15 | medium @0: Text;
16 | address @1: Text;
17 | }
18 |
19 | struct PostAccount3PIDEmailRequestCapn {
20 | path @0: Text;
21 | clientSecret @1: Text;
22 | email @2: Text;
23 | sendAttempt @3: Text;
24 | nextLink @4: Text;
25 | idServer @5: Text;
26 | }
27 |
28 | struct PostAccount3PIDEmailResponseCapn {
29 | sid @0: Text;
30 | }
31 |
32 | struct PostAccount3PIDMsisdnRequestCapn {
33 | path @0: Text;
34 | clientSecret @1: Text;
35 | country @2: Text;
36 | phoneNumber @3: Text;
37 | sendAttempt @4: Text;
38 | nextLink @5: Text;
39 | idServer @6: Text;
40 | }
41 |
42 | struct PostAccount3PIDMsisdnResponseCapn {
43 | sid @0: Text;
44 | }
45 |
46 | struct PostAccount3PIDRequestCapn {
47 | threePIDCreds @0: ThreePidCredentialsCapn;
48 | bind @1: Bool;
49 | }
50 |
51 | struct ThirdPartyIdentifierCapn {
52 | medium @0: Text;
53 | address @1: Text;
54 | validatedAt @2: Int64;
55 | addedAt @3: Int64;
56 | }
57 |
58 | struct ThreePidCredentialsCapn {
59 | clientSecret @0: Text;
60 | idServer @1: Text;
61 | sid @2: Text;
62 | }
63 |
64 | struct GetAccountWhoAmIResponseCapn {
65 | userID @0: Text;
66 | }
67 |
--------------------------------------------------------------------------------
/plugins/message/external/device.capn:
--------------------------------------------------------------------------------
1 | @0xd3996cfefe9023b6;
2 | using Go = import "/go.capnp";
3 | $Go.package("external");
4 | $Go.import("github.com/finogeeks/ligase/plugins/message/external");
5 |
6 | struct DelDeviceRequestCapn {
7 | deviceID @0: Text;
8 | auth @1: DeviceAuthDictCapn;
9 | }
10 |
11 | struct DeviceCapn {
12 | deviceID @0: Text;
13 | displayName @1: Text;
14 | lastSeenIP @2: Text;
15 | lastSeenTs @3: Int64;
16 | userID @4: Text;
17 | }
18 |
19 | struct DeviceAuthDictCapn {
20 | type @0: Text;
21 | session @1: Text;
22 | password @2: Text;
23 | user @3: Text;
24 | }
25 |
26 | struct DeviceListCapn {
27 | devices @0: List(DeviceCapn);
28 | }
29 |
30 | struct GetDeviceRequestCapn {
31 | deviceID @0: Text;
32 | }
33 |
34 | struct PutDeviceRequestCapn {
35 | deviceID @0: Text;
36 | displayName @1: Text;
37 | }
38 |
--------------------------------------------------------------------------------
/plugins/message/external/filter.capn:
--------------------------------------------------------------------------------
1 | @0xacdcc264a86fbe56;
2 | using Go = import "/go.capnp";
3 | $Go.package("external");
4 | $Go.import("github.com/finogeeks/ligase/plugins/message/external");
5 |
6 | struct EventFilterCapn {
7 | limit @0: Int64;
8 | notSenders @1: List(Text);
9 | notTypes @2: List(Text);
10 | senders @3: List(Text);
11 | types @4: List(Text);
12 | }
13 |
14 | struct GetUserFilterRequestCapn {
15 | userID @0: Text;
16 | filterID @1: Text;
17 | }
18 |
19 | struct PostUserFilterResponseCapn {
20 | filterID @0: Text;
21 | }
22 |
23 | struct RoomEventFilterCapn {
24 | eventFilter @0: EventFilterCapn;
25 | notRooms @1: List(Text);
26 | rooms @2: List(Text);
27 | containsURL @3: Bool;
28 | }
29 |
--------------------------------------------------------------------------------
/plugins/message/external/login.capn:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/plugins/message/external/login.capn
--------------------------------------------------------------------------------
/plugins/message/external/modules.capn:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/plugins/message/external/modules.capn
--------------------------------------------------------------------------------
/plugins/message/external/presence.capn:
--------------------------------------------------------------------------------
1 | @0xfef752e0bb5f7b2f;
2 | using Go = import "/go.capnp";
3 | $Go.package("external");
4 | $Go.import("github.com/finogeeks/ligase/plugins/message/external");
5 |
6 | struct GetPresenceListRequestCapn {
7 | userID @0: Text;
8 | }
9 |
10 | struct GetPresenceListResponseCapn {
11 | presenceList @0: List(PresenceJSONCapn);
12 | }
13 |
14 | struct GetPresenceRequestCapn {
15 | userID @0: Text;
16 | }
17 |
18 | struct GetPresenceResponseCapn {
19 | presence @0: Text;
20 | lastActiveAgo @1: Int64;
21 | statusMsg @2: Text;
22 | extStatusMsg @3: Text;
23 | currentlyActive @4: Bool;
24 | }
25 |
26 | struct PresenceJSONCapn {
27 | avatarURL @0: Text;
28 | displayName @1: Text;
29 | lastActiveAgo @2: Int64;
30 | presence @3: Text;
31 | currentlyActive @4: Bool;
32 | userID @5: Text;
33 | statusMsg @6: Text;
34 | extStatusMsg @7: Text;
35 | }
36 |
37 | struct PresenceListJSONCapn {
38 | content @0: PresenceJSONCapn;
39 | typ @1: Text;
40 | }
41 |
42 | struct PutPresenceRequestCapn {
43 | userID @0: Text;
44 | presence @1: Text;
45 | statusMsg @2: Text;
46 | extStatusMsg @3: Text;
47 | }
48 |
49 | struct PostPresenceListRequestCapn {
50 | userID @0: Text;
51 | invite @1: List(Text);
52 | drop @2: List(Text);
53 | }
--------------------------------------------------------------------------------
/plugins/message/external/profile.capn:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/plugins/message/external/profile.capn
--------------------------------------------------------------------------------
/plugins/message/external/rcs.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package external
16 |
17 | const (
18 | RCSFriendshipTypeBot = "bot"
19 | )
20 |
21 | type GetFriendshipsRequest struct {
22 | Type string `json:"type"`
23 | }
24 |
25 | type GetFriendshipsResponse struct {
26 | Friendships []Friendship `json:"friendships"`
27 | }
28 |
29 | type Friendship struct {
30 | FcID string `json:"fcid"`
31 | ToFcID string `json:"toFcid"`
32 | RoomID string `json:"roomId"`
33 | IsBot bool `json:"isBot"`
34 | Remark string `json:"remark"`
35 | }
36 |
37 | type GetFriendshipRequest struct {
38 | FcID string `json:"fcid"`
39 | ToFcID string `json:"toFcid"`
40 | }
41 |
42 | type GetFriendshipResponse struct {
43 | FcID string `json:"fcid"`
44 | ToFcID string `json:"to_fcid"`
45 | RoomID string `json:"room_id"`
46 | FcIDState string `json:"fcid_state"`
47 | ToFcIDState string `json:"to_fcid_state"`
48 | }
49 |
--------------------------------------------------------------------------------
/plugins/message/external/register.capn:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/plugins/message/external/register.capn
--------------------------------------------------------------------------------
/plugins/message/external/room.capn:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/plugins/message/external/room.capn
--------------------------------------------------------------------------------
/plugins/message/external/serverCfg.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package external
16 |
17 | type ServerNameCfgRequest struct {
18 | Type string `json:"type"`
19 | ServerNames []string `json:"server_names"`
20 | }
21 |
22 | type GetServerNamesResponse struct {
23 | ServerNames []string `json:"server_names"`
24 | }
25 |
--------------------------------------------------------------------------------
/plugins/message/external/setting.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package external
16 |
17 | type ReqGetSettingRequest struct {
18 | SettingKey string `json:"settingKey"`
19 | }
20 |
21 | type ReqPutSettingRequest struct {
22 | SettingKey string
23 | Content string
24 | }
25 |
--------------------------------------------------------------------------------
/plugins/message/external/userData.capn:
--------------------------------------------------------------------------------
1 | @0x87ebf98ac187faed;
2 | using Go = import "/go.capnp";
3 | $Go.package("external");
4 | $Go.import("github.com/finogeeks/ligase/plugins/message/external");
5 |
6 | struct GetUserProfileAvatarURLRequestCapn {
7 | userID @0: Text;
8 | }
9 |
10 | struct GetUserProfileDisplayNameRequestCapn {
11 | userID @0: Text;
12 | }
13 |
14 | struct GetUserProfileRequestCapn {
15 | userID @0: Text;
16 | }
17 |
18 | struct PostUserSearchRequestCapn {
19 | searchTerm @0: Text;
20 | limit @1: Int64;
21 | }
22 |
23 | struct PostUserSearchResponseCapn {
24 | results @0: List(UserCapn);
25 | limited @1: Bool;
26 | }
27 |
28 | struct PutUserProfileAvatarURLRequestCapn {
29 | userID @0: Text;
30 | avatarURL @1: Text;
31 | }
32 |
33 | struct PutUserProfileDisplayNameRequestCapn {
34 | userID @0: Text;
35 | displayName @1: Text;
36 | }
37 |
38 | struct UserCapn {
39 | userID @0: Text;
40 | displayName @1: Text;
41 | avatarURL @2: Text;
42 | }
43 |
--------------------------------------------------------------------------------
/plugins/message/external/util.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package external
16 |
17 | import (
18 | "net"
19 | "net/http"
20 | "strings"
21 | )
22 |
23 | func GetRemoteIP(r *http.Request) string {
24 | xRealIP := r.Header.Get("X-Real-Ip")
25 | xForwardedFor := r.Header.Get("X-Forwarded-For")
26 |
27 | // If both empty, return IP from remote address
28 | if xRealIP == "" && xForwardedFor == "" {
29 | var remoteIP string
30 |
31 | // If there are colon in remote address, remove the port number
32 | // otherwise, return remote address as is
33 | if strings.ContainsRune(r.RemoteAddr, ':') {
34 | remoteIP, _, _ = net.SplitHostPort(r.RemoteAddr)
35 | } else {
36 | remoteIP = r.RemoteAddr
37 | }
38 |
39 | return remoteIP
40 | }
41 |
42 | for _, address := range strings.Split(xForwardedFor, ",") {
43 | return strings.TrimSpace(address)
44 | }
45 |
46 | // If nothing succeed, return X-Real-IP
47 | return xRealIP
48 | }
49 |
--------------------------------------------------------------------------------
/plugins/message/external/visibilityrange.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package external
16 |
17 | // GET /_matrix/client/r0/rooms/{roomID}/visibility_range
18 | type GetRoomVisibilityRangeRequest struct {
19 | UserID string `json:"userID"`
20 | RoomID string `json:"roomID"`
21 | }
22 |
23 | type GetRoomVisibilityRangeResponse struct {
24 | Joined map[string]MemberContent `json:"joined"`
25 | }
26 |
--------------------------------------------------------------------------------
/plugins/message/external/voip.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package external
16 |
17 | import (
18 | "github.com/finogeeks/ligase/skunkworks/gomatrix"
19 | )
20 |
21 | //GET /_matrix/client/r0/voip/turnServer
22 | type PostVoipTurnServerResponse gomatrix.RespTurnServer
23 |
--------------------------------------------------------------------------------
/plugins/message/internals/msg.capnp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/finogeeks/Ligase/9835270b055a80602ecff9037274aad8e9542fb4/plugins/message/internals/msg.capnp
--------------------------------------------------------------------------------
/plugins/processors/HandlerProcessor.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package processor
16 |
17 | import (
18 | "github.com/finogeeks/ligase/core"
19 | )
20 |
21 | type HandlerProcessor struct {
22 | }
23 |
24 | func init() {
25 | core.RegisterProcessor("handler", newHandlerProcessor)
26 | }
27 |
28 | func newHandlerProcessor(conf interface{}) (core.IProcessor, error) {
29 | k := new(HandlerProcessor)
30 | return k, nil
31 | }
32 |
33 | func (p *HandlerProcessor) OnMultiplexerMessage(serviceID string, msg interface{}) (interface{}, error) {
34 | return nil, nil
35 | }
36 |
37 | func (m *HandlerProcessor) OnMessage(topic string, partition int32, data []byte) ([]byte, error) {
38 | return nil, nil
39 | }
40 |
41 | func (m *HandlerProcessor) PreStart() {
42 | }
43 |
44 | func (m *HandlerProcessor) Start() {
45 | }
46 |
--------------------------------------------------------------------------------
/plugins/transport/kafkaTransport.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package transport
16 |
17 | import (
18 | "log"
19 |
20 | "github.com/finogeeks/ligase/core"
21 | )
22 |
23 | func init() {
24 | core.RegisterTransport("kafka", NewKafkaTransport)
25 | }
26 |
27 | func NewKafkaTransport(conf interface{}) (core.ITransport, error) {
28 | k := new(KafkaTransport)
29 | return k, nil
30 | }
31 |
32 | type KafkaTransport struct {
33 | baseTransport
34 | }
35 |
36 | func (t *KafkaTransport) AddChannel(dir int, id, topic, grp string, conf interface{}) bool {
37 | _, ok := t.channels.Load(id)
38 | if ok {
39 | return true
40 | }
41 |
42 | channel, err := core.GetChannel("kafka", conf)
43 | if err != nil {
44 | return false
45 | }
46 | channel.Init(t.logPorf)
47 | channel.SetDir(dir)
48 | channel.SetTopic(topic)
49 | channel.SetID(id)
50 | channel.SetGroup(grp)
51 |
52 | t.channels.Store(id, channel)
53 |
54 | log.Printf("KafkaTransport AddChannel broker:%s dir:%d id:%s topic:%s grp:%s", t.brokers, dir, id, topic, grp)
55 |
56 | return true
57 | }
58 |
--------------------------------------------------------------------------------
/publicroomsapi/README.md:
--------------------------------------------------------------------------------
1 | # Public rooms API
2 |
3 | This server is responsible for serving requests hitting `/publicRooms` and `/directory/list/room/{roomID}` as per:
4 |
5 | https://matrix.org/docs/spec/client_server/r0.2.0.html#listing-rooms
6 |
--------------------------------------------------------------------------------
/pushapi/pushapi.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package pushapi
16 |
17 | import (
18 | "github.com/finogeeks/ligase/common"
19 | "github.com/finogeeks/ligase/common/basecomponent"
20 | "github.com/finogeeks/ligase/model/service"
21 | "github.com/finogeeks/ligase/pushapi/api"
22 | "github.com/finogeeks/ligase/storage/model"
23 | )
24 |
25 | func SetupPushAPIComponent(
26 | base *basecomponent.BaseDendrite,
27 | redisCache service.Cache,
28 | rpcCli *common.RpcClient,
29 | ) model.PushAPIDatabase {
30 | pushDB := base.CreatePushApiDB()
31 |
32 | apiConsumer := api.NewInternalMsgConsumer(
33 | *base.Cfg, pushDB, redisCache, rpcCli,
34 | )
35 | apiConsumer.Start()
36 | return pushDB
37 | }
38 |
--------------------------------------------------------------------------------
/pushsender/pushSender.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package pushsender
16 |
17 | import (
18 | "github.com/finogeeks/ligase/common"
19 | "github.com/finogeeks/ligase/common/basecomponent"
20 | "github.com/finogeeks/ligase/pushsender/consumers"
21 | "github.com/finogeeks/ligase/skunkworks/log"
22 | "github.com/finogeeks/ligase/storage/model"
23 | )
24 |
25 | func SetupPushSenderComponent(
26 | base *basecomponent.BaseDendrite,
27 | rpcClient *common.RpcClient,
28 | ) (model.PushAPIDatabase, *consumers.PushDataConsumer) {
29 | pushDB := base.CreatePushApiDB()
30 |
31 | pushConsumer := consumers.NewPushDataConsumer(
32 | base.Cfg, pushDB, rpcClient,
33 | )
34 | if err := pushConsumer.Start(); err != nil {
35 | log.Panicw("failed to start push data consumer", log.KeysAndValues{"error", err})
36 | }
37 |
38 | return pushDB, pushConsumer
39 | }
40 |
--------------------------------------------------------------------------------
/roomserver/processors/fedProcessor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package processors
19 |
20 | import (
21 | "context"
22 |
23 | "github.com/finogeeks/ligase/model/service/roomserverapi"
24 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
25 | //log "github.com/finogeeks/ligase/skunkworks/log"
26 | )
27 |
28 | type FedProcessor struct {
29 | Alias AliasProcessor
30 | }
31 |
32 | func (r *FedProcessor) OnRoomEvent(
33 | ctx context.Context,
34 | event *gomatrixserverlib.Event,
35 | ) error {
36 | if event.Type() == "m.room.aliases" {
37 | var request roomserverapi.SetRoomAliasRequest
38 | var response roomserverapi.SetRoomAliasResponse
39 | var payload roomAliasesContent
40 |
41 | err := json.Unmarshal(event.Content(), &payload)
42 | if err != nil {
43 | return err
44 | }
45 |
46 | for _, alias := range payload.Aliases {
47 | request.Alias = alias
48 | request.RoomID = event.RoomID()
49 | request.UserID = event.Sender()
50 | err = r.Alias.AllocRoomAlias(ctx, &request, &response)
51 | if err != nil {
52 | return err
53 | }
54 | }
55 |
56 | }
57 |
58 | return nil
59 | }
60 |
--------------------------------------------------------------------------------
/skunkworks/gomatrix/README.md:
--------------------------------------------------------------------------------
1 | # gomatrix
2 | [](https://godoc.org/github.com/matrix-org/gomatrix)
3 |
4 | A Golang Matrix client.
5 |
6 | **THIS IS UNDER ACTIVE DEVELOPMENT: BREAKING CHANGES ARE FREQUENT.**
7 |
--------------------------------------------------------------------------------
/skunkworks/gomatrix/hooks/install.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | DOT_GIT="$(dirname $0)/../.git"
4 |
5 | ln -s "../../hooks/pre-commit" "$DOT_GIT/hooks/pre-commit"
--------------------------------------------------------------------------------
/skunkworks/gomatrix/hooks/pre-commit:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | set -eu
4 |
5 | golint
6 | misspell --error .
7 |
8 | # gofmt doesn't exit with an error code if the files don't match the expected
9 | # format. So we have to run it and see if it outputs anything.
10 | if gofmt -l -s . 2>&1 | read
11 | then
12 | echo "Error: not all code had been formatted with gofmt."
13 | echo "Fixing the following files"
14 | gofmt -s -w -l .
15 | echo
16 | echo "Please add them to the commit"
17 | git status --short
18 | exit 1
19 | fi
20 |
21 | ineffassign .
22 |
23 | go fmt
24 | go tool vet --all --shadow .
25 | gocyclo -over 12 .
26 | go test -timeout 5s -test.v
27 |
--------------------------------------------------------------------------------
/skunkworks/gomatrix/room.go:
--------------------------------------------------------------------------------
1 | package gomatrix
2 |
3 | // Room represents a single Matrix room.
4 | type Room struct {
5 | ID string
6 | State map[string]map[string]*Event
7 | }
8 |
9 | // UpdateState updates the room's current state with the given Event. This will clobber events based
10 | // on the type/state_key combination.
11 | func (room Room) UpdateState(event *Event) {
12 | _, exists := room.State[event.Type]
13 | if !exists {
14 | room.State[event.Type] = make(map[string]*Event)
15 | }
16 | room.State[event.Type][*event.StateKey] = event
17 | }
18 |
19 | // GetStateEvent returns the state event for the given type/state_key combo, or nil.
20 | func (room Room) GetStateEvent(eventType string, stateKey string) *Event {
21 | stateEventMap, _ := room.State[eventType]
22 | event, _ := stateEventMap[stateKey]
23 | return event
24 | }
25 |
26 | // GetMembershipState returns the membership state of the given user ID in this room. If there is
27 | // no entry for this member, 'leave' is returned for consistency with left users.
28 | func (room Room) GetMembershipState(userID string) string {
29 | state := "leave"
30 | event := room.GetStateEvent("m.room.member", userID)
31 | if event != nil {
32 | membershipState, found := event.Content["membership"]
33 | if found {
34 | mState, isString := membershipState.(string)
35 | if isString {
36 | state = mState
37 | }
38 | }
39 | }
40 | return state
41 | }
42 |
43 | // NewRoom creates a new Room with the given ID
44 | func NewRoom(roomID string) *Room {
45 | // Init the State map and return a pointer to the Room
46 | return &Room{
47 | ID: roomID,
48 | State: make(map[string]map[string]*Event),
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/skunkworks/gomatrix/userids_examples_test.go:
--------------------------------------------------------------------------------
1 | package gomatrix
2 |
3 | import "fmt"
4 |
5 | func ExampleEncodeUserLocalpart() {
6 | localpart := EncodeUserLocalpart("Alph@Bet_50up")
7 | fmt.Println(localpart)
8 | // Output: _alph=40_bet__50up
9 | }
10 |
11 | func ExampleDecodeUserLocalpart() {
12 | localpart, err := DecodeUserLocalpart("_alph=40_bet__50up")
13 | if err != nil {
14 | panic(err)
15 | }
16 | fmt.Println(localpart)
17 | // Output: Alph@Bet_50up
18 | }
19 |
20 | func ExampleExtractUserLocalpart() {
21 | localpart, err := ExtractUserLocalpart("@alice:matrix.org")
22 | if err != nil {
23 | panic(err)
24 | }
25 | fmt.Println(localpart)
26 | // Output: alice
27 | }
28 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/README.md:
--------------------------------------------------------------------------------
1 | # homeserverlib
2 |
3 | fork from github
4 | Go library for common functions needed by matrix servers.
5 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/appservice.go:
--------------------------------------------------------------------------------
1 | /* Copyright 2018 New Vector Ltd
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package gomatrixserverlib
17 |
18 | // ApplicationServiceTransaction is the transaction that is sent off to an
19 | // application service.
20 | type ApplicationServiceTransaction struct {
21 | Events []ClientEvent `json:"events"`
22 | }
23 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/edu.go:
--------------------------------------------------------------------------------
1 | /* Licensed under the Apache License, Version 2.0 (the "License");
2 | * you may not use this file except in compliance with the License.
3 | * You may obtain a copy of the License at
4 | *
5 | * http://www.apache.org/licenses/LICENSE-2.0
6 | *
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 |
14 | package gomatrixserverlib
15 |
16 | // EDU represents a EDU received via federation
17 | // https://matrix.org/docs/spec/server_server/unstable.html#edus
18 | type EDU struct {
19 | Type string `json:"edu_type"`
20 | Origin string `json:"origin"`
21 | Destination string `json:"destination"`
22 | Content rawJSON `json:"content"`
23 | }
24 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/event_examples_test.go:
--------------------------------------------------------------------------------
1 | /* Copyright 2016-2017 Vector Creations Ltd
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package gomatrixserverlib
17 |
18 | import "fmt"
19 |
20 | func ExampleSplitID() {
21 | localpart, domain, err := SplitID('@', "@alice:localhost:8080")
22 | if err != nil {
23 | panic(err)
24 | }
25 | fmt.Println(localpart, domain)
26 | // Output: alice localhost:8080
27 | }
28 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/eventcontent_test.go:
--------------------------------------------------------------------------------
1 | /* Copyright 2016-2017 Vector Creations Ltd
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package gomatrixserverlib
17 |
18 | import (
19 | "encoding/json"
20 | "testing"
21 | )
22 |
23 | func TestLevelJSONValueValid(t *testing.T) {
24 | var values []levelJSONValue
25 | input := `[0,"1",2.0]`
26 | if err := json.Unmarshal([]byte(input), &values); err != nil {
27 | t.Fatal("Unexpected error unmarshalling ", input, ": ", err)
28 | }
29 | for i, got := range values {
30 | want := i
31 | if !got.exists {
32 | t.Fatalf("Wanted entry %d to exist", want)
33 | }
34 | if int64(want) != got.value {
35 | t.Fatalf("Wanted %d got %q", want, got.value)
36 | }
37 | }
38 | }
39 |
40 | func TestLevelJSONValueInvalid(t *testing.T) {
41 | var values []levelJSONValue
42 | inputs := []string{
43 | `[{}]`, `[[]]`, `["not a number"]`, `["0.0"]`,
44 | }
45 |
46 | for _, input := range inputs {
47 | if err := json.Unmarshal([]byte(input), &values); err == nil {
48 | t.Fatalf("Unexpected success when unmarshalling %q", input)
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/federationtypes_test.go:
--------------------------------------------------------------------------------
1 | package gomatrixserverlib
2 |
3 | import (
4 | "encoding/json"
5 | "testing"
6 | )
7 |
8 | func TestRespSendJoinMarshalJSON(t *testing.T) {
9 | inputData := `{"pdus":[],"auth_chain":[]}`
10 | var input RespState
11 | if err := json.Unmarshal([]byte(inputData), &input); err != nil {
12 | t.Fatal(err)
13 | }
14 |
15 | gotBytes, err := json.Marshal(RespSendJoin(input))
16 | if err != nil {
17 | t.Fatal(err)
18 | }
19 |
20 | want := `[200,{"state":[],"auth_chain":[]}]`
21 | got := string(gotBytes)
22 |
23 | if want != got {
24 | t.Errorf("json.Marshal(RespSendJoin(%q)): wanted %q, got %q", inputData, want, got)
25 | }
26 | }
27 |
28 | func TestRespSendJoinUnmarshalJSON(t *testing.T) {
29 | inputData := `[200,{"state":[],"auth_chain":[]}]`
30 | var input RespSendJoin
31 | if err := json.Unmarshal([]byte(inputData), &input); err != nil {
32 | t.Fatal(err)
33 | }
34 |
35 | gotBytes, err := json.Marshal(RespState(input))
36 | if err != nil {
37 | t.Fatal(err)
38 | }
39 |
40 | want := `{"pdus":[],"auth_chain":[]}`
41 | got := string(gotBytes)
42 |
43 | if want != got {
44 | t.Errorf("json.Marshal(RespSendJoin(%q)): wanted %q, got %q", inputData, want, got)
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/hex_string.go:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 New Vector Ltd
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package gomatrixserverlib
17 |
18 | import (
19 | "encoding/hex"
20 | //"encoding/json"
21 | )
22 |
23 | // A HexString is a string of bytes that are hex encoded when used in JSON.
24 | // The bytes encoded using hex when marshalled as JSON.
25 | // When the bytes are unmarshalled from JSON they are decoded from hex.
26 | type HexString []byte
27 |
28 | // MarshalJSON encodes the bytes as hex and then encodes the hex as a JSON string.
29 | // This takes a value receiver so that maps and slices of HexString encode correctly.
30 | func (h HexString) MarshalJSON() ([]byte, error) {
31 | return json.Marshal(hex.EncodeToString(h))
32 | }
33 |
34 | // UnmarshalJSON decodes a JSON string and then decodes the resulting hex.
35 | // This takes a pointer receiver because it needs to write the result of decoding.
36 | func (h *HexString) UnmarshalJSON(raw []byte) (err error) {
37 | var str string
38 | if err = json.Unmarshal(raw, &str); err != nil {
39 | return
40 | }
41 |
42 | *h, err = hex.DecodeString(str)
43 | return
44 | }
45 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/hooks/install.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | DOT_GIT="$(dirname $0)/../.git"
4 |
5 | ln -s "../../hooks/pre-commit" "$DOT_GIT/hooks/pre-commit"
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/hooks/pre-commit:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | set -eu
4 |
5 | # make the GIT_DIR and GIT_INDEX_FILE absolute, before we change dir
6 | export GIT_DIR=$(readlink -f `git rev-parse --git-dir`)
7 | if [ -n "${GIT_INDEX_FILE:+x}" ]; then
8 | export GIT_INDEX_FILE=$(readlink -f "$GIT_INDEX_FILE")
9 | fi
10 |
11 | wd=`pwd`
12 |
13 | # create a temp dir. The `trap` incantation will ensure that it is removed
14 | # again when this script completes.
15 | tmpdir=`mktemp -d`
16 | trap 'rm -rf "$tmpdir"' EXIT
17 | cd "$tmpdir"
18 |
19 | # get a clean copy of the index (ie, what has been `git add`ed), so that we can
20 | # run the checks against what we are about to commit, rather than what is in
21 | # the working copy.
22 | git checkout-index -a
23 |
24 | echo "Installing lint search engine..."
25 | go get github.com/alecthomas/gometalinter/
26 | gometalinter --config=linter.json --install --update --debug
27 |
28 | echo "Testing..."
29 | go test
30 |
31 | echo "Looking for lint..."
32 | gometalinter --config=linter.json
33 |
34 | echo "Double checking spelling..."
35 | misspell -error src *.md
36 |
37 | echo "Done!"
38 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/linter.json:
--------------------------------------------------------------------------------
1 | {
2 | "Deadline": "5m",
3 | "Enable": [
4 | "vet",
5 | "vetshadow",
6 | "gotype",
7 | "deadcode",
8 | "gocyclo",
9 | "golint",
10 | "varcheck",
11 | "structcheck",
12 | "maligned",
13 | "ineffassign",
14 | "gas",
15 | "misspell",
16 | "gosimple",
17 | "megacheck",
18 | "unparam",
19 | "goimports",
20 | "goconst",
21 | "unconvert",
22 | "errcheck",
23 | "interfacer",
24 | "testify"
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/stateresolution_test.go:
--------------------------------------------------------------------------------
1 | package gomatrixserverlib
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | const (
8 | sha1OfEventID1A = "\xe5\x89,\xa2\x1cF<&\xf3\rf}\xde\xa5\xef;\xddK\xaaS"
9 | sha1OfEventID2A = "\xa4\xe4\x10\x1b}\x1a\xf9`\x94\x10\xa3\x84+\xae\x06\x8d\x16A\xfc>"
10 | sha1OfEventID3B = "\xca\xe8\xde\xb6\xa3\xb6\xee\x01\xc4\xbc\xd0/\x1b\x1c2\x0c\xd3\xa4\xe9\xcb"
11 | )
12 |
13 | func TestConflictEventSorter(t *testing.T) {
14 | input := []Event{
15 | {fields: eventFields{Depth: 1, EventID: "@1:a"}},
16 | {fields: eventFields{Depth: 2, EventID: "@2:a"}},
17 | {fields: eventFields{Depth: 2, EventID: "@3:b"}},
18 | }
19 | got := sortConflictedEventsByDepthAndSHA1(input)
20 | want := []conflictedEvent{
21 | {depth: 1, event: &input[0]},
22 | {depth: 2, event: &input[2]},
23 | {depth: 2, event: &input[1]},
24 | }
25 | copy(want[0].eventIDSHA1[:], sha1OfEventID1A)
26 | copy(want[1].eventIDSHA1[:], sha1OfEventID3B)
27 | copy(want[2].eventIDSHA1[:], sha1OfEventID2A)
28 | if len(want) != len(got) {
29 | t.Fatalf("Different length: wanted %d, got %d", len(want), len(got))
30 | }
31 | for i := range want {
32 | if want[i] != got[i] {
33 | t.Fatalf("Different element at index %d: wanted %#v got %#v", i, want[i], got[i])
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/timestamp.go:
--------------------------------------------------------------------------------
1 | package gomatrixserverlib
2 |
3 | import (
4 | "time"
5 | )
6 |
7 | // A Timestamp is a millisecond posix timestamp.
8 | type Timestamp uint64
9 |
10 | // AsTimestamp turns a time.Time into a millisecond posix timestamp.
11 | func AsTimestamp(t time.Time) Timestamp {
12 | return Timestamp(t.UnixNano() / 1000000)
13 | }
14 |
15 | // Time turns a millisecond posix timestamp into a UTC time.Time
16 | func (t Timestamp) Time() time.Time {
17 | return time.Unix(int64(t)/1000, (int64(t)%1000)*1000000).UTC()
18 | }
19 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixserverlib/travis.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -eux
4 |
5 | cd `dirname $0`
6 |
7 | # -u so that if this is run on a dev box, we get the latest deps, as
8 | # we do on travis.
9 |
10 | go get -u \
11 | github.com/alecthomas/gometalinter \
12 | golang.org/x/crypto/ed25519 \
13 | github.com/matrix-org/util \
14 | github.com/matrix-org/gomatrix \
15 | github.com/tidwall/gjson \
16 | github.com/tidwall/sjson \
17 | github.com/pkg/errors \
18 | gopkg.in/yaml.v2 \
19 |
20 | ./hooks/pre-commit
21 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixutil/README.md:
--------------------------------------------------------------------------------
1 | # util
2 |
3 | [](https://godoc.org/github.com/matrix-org/util)
4 | [](https://travis-ci.org/matrix-org/util)
5 | [](https://coveralls.io/github/matrix-org/util)
6 |
7 | A loose collection of Golang functions that we use at matrix.org
8 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixutil/context.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import (
4 | "context"
5 |
6 | log "github.com/finogeeks/ligase/skunkworks/log"
7 | )
8 |
9 | // contextKeys is a type alias for string to namespace Context keys per-package.
10 | type contextKeys string
11 |
12 | // ctxValueRequestID is the key to extract the request ID for an HTTP request
13 | const ctxValueRequestID = contextKeys("requestid")
14 |
15 | // GetRequestID returns the request ID associated with this context, or the empty string
16 | // if one is not associated with this context.
17 | func GetRequestID(ctx context.Context) string {
18 | id := ctx.Value(ctxValueRequestID)
19 | if id == nil {
20 | return ""
21 | }
22 | return id.(string)
23 | }
24 |
25 | const ctxValueLogFields = contextKeys("logFields")
26 |
27 | func GetLogFields(ctx context.Context) log.KeysAndValues {
28 | fields := ctx.Value(ctxValueLogFields)
29 | if fields == nil {
30 | return log.KeysAndValues{"context", "missing"}
31 | }
32 | return fields.(log.KeysAndValues)
33 | }
34 |
35 | // ContextWithLogger creates a new context, which will use the given logger.
36 | func ContextWithLogFields(ctx context.Context, fields log.KeysAndValues) context.Context {
37 | return context.WithValue(ctx, ctxValueLogFields, fields)
38 | }
39 |
--------------------------------------------------------------------------------
/skunkworks/gomatrixutil/hooks/install.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | DOT_GIT="$(dirname $0)/../.git"
4 |
5 | ln -s "../../hooks/pre-commit" "$DOT_GIT/hooks/pre-commit"
--------------------------------------------------------------------------------
/skunkworks/gomatrixutil/hooks/pre-commit:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | set -eu
4 |
5 | golint
6 | go fmt
7 | go tool vet --all --shadow .
8 | gocyclo -over 12 .
9 | go test -timeout 5s -test.v
10 |
--------------------------------------------------------------------------------
/skunkworks/log/logger.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | type Logger interface {
4 | Debug(args ...interface{})
5 | Debugf(template string, args ...interface{})
6 | Debugln(args ...interface{})
7 | Debugw(msg string, kv KeysAndValues)
8 | Info(args ...interface{})
9 | Infof(template string, args ...interface{})
10 | Infoln(args ...interface{})
11 | Infow(msg string, kv KeysAndValues)
12 | Warn(args ...interface{})
13 | Warnf(template string, args ...interface{})
14 | Warnln(args ...interface{})
15 | Warnw(msg string, kv KeysAndValues)
16 | Error(args ...interface{})
17 | Errorf(template string, args ...interface{})
18 | Errorln(args ...interface{})
19 | Errorw(msg string, kv KeysAndValues)
20 | DPanic(args ...interface{})
21 | DPanicf(template string, args ...interface{})
22 | DPanicln(args ...interface{})
23 | DPanicw(msg string, kv KeysAndValues)
24 | Panic(args ...interface{})
25 | Panicf(template string, args ...interface{})
26 | Panicln(args ...interface{})
27 | Panicw(msg string, kv KeysAndValues)
28 | Fatal(args ...interface{})
29 | Fatalf(template string, args ...interface{})
30 | Fatalln(args ...interface{})
31 | Fatalw(msg string, kv KeysAndValues)
32 | }
33 |
--------------------------------------------------------------------------------
/skunkworks/monitor/go-client/monitor/counter.go:
--------------------------------------------------------------------------------
1 | package monitor
2 |
3 | import (
4 | "github.com/prometheus/client_golang/prometheus"
5 | )
6 |
7 | type counter struct {
8 | prometheus.Counter
9 | enable bool
10 | }
11 |
12 | func (c *counter) Inc() {
13 | if c.enable {
14 | c.Counter.Inc()
15 | }
16 | }
17 |
18 | func (c *counter) Add(v float64) {
19 | if c.enable {
20 | c.Counter.Add(v)
21 | }
22 | }
23 |
24 | type labeledCounter struct {
25 | *prometheus.CounterVec
26 | enable bool
27 | }
28 |
29 | func (c *labeledCounter) WithLabelValues(lvs ...string) Counter {
30 | if c.enable {
31 | return &counter{c.CounterVec.WithLabelValues(lvs...), true}
32 | } else {
33 | return &counter{enable: false}
34 | }
35 | }
36 |
37 | func (c *labeledCounter) With(labels Labels) Counter {
38 | if c.enable {
39 | return &counter{c.CounterVec.With(prometheus.Labels(labels)), true}
40 | } else {
41 | return &counter{enable: false}
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/skunkworks/monitor/go-client/monitor/gauge.go:
--------------------------------------------------------------------------------
1 | package monitor
2 |
3 | import (
4 | "github.com/prometheus/client_golang/prometheus"
5 | )
6 |
7 | type gauge struct {
8 | prometheus.Gauge
9 | enable bool
10 | }
11 |
12 | func (g *gauge) Set(v float64) {
13 | if g.enable {
14 | g.Gauge.Set(v)
15 | }
16 | }
17 |
18 | func (g *gauge) Inc() {
19 | if g.enable {
20 | g.Gauge.Inc()
21 | }
22 | }
23 |
24 | func (g *gauge) Dec() {
25 | if g.enable {
26 | g.Gauge.Dec()
27 | }
28 | }
29 |
30 | func (g *gauge) Add(v float64) {
31 | if g.enable {
32 | g.Gauge.Add(v)
33 | }
34 | }
35 |
36 | func (g *gauge) Sub(v float64) {
37 | if g.enable {
38 | g.Gauge.Sub(v)
39 | }
40 | }
41 |
42 | func (g *gauge) SetToCurrentTime() {
43 | if g.enable {
44 | g.Gauge.SetToCurrentTime()
45 | }
46 | }
47 |
48 | type labeledGauge struct {
49 | *prometheus.GaugeVec
50 | enable bool
51 | }
52 |
53 | func (g *labeledGauge) WithLabelValues(lvs ...string) Gauge {
54 | if g.enable {
55 | return &gauge{g.GaugeVec.WithLabelValues(lvs...), true}
56 | } else {
57 | return &gauge{enable: false}
58 | }
59 | }
60 |
61 | func (g *labeledGauge) With(labels Labels) Gauge {
62 | if g.enable {
63 | return &gauge{g.GaugeVec.With(prometheus.Labels(labels)), true}
64 | } else {
65 | return &gauge{enable: false}
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/skunkworks/monitor/go-client/monitor/histogram.go:
--------------------------------------------------------------------------------
1 | package monitor
2 |
3 | import (
4 | "github.com/prometheus/client_golang/prometheus"
5 | )
6 |
7 | type histogram struct {
8 | prometheus.Observer
9 | enable bool
10 | }
11 |
12 | func (h *histogram) Observe(v float64) {
13 | if h.enable {
14 | h.Observer.Observe(v)
15 | }
16 | }
17 |
18 | type labeledHistogram struct {
19 | *prometheus.HistogramVec
20 | enable bool
21 | }
22 |
23 | func (h *labeledHistogram) WithLabelValues(lvs ...string) Histogram {
24 | if h.enable {
25 | return &histogram{h.HistogramVec.WithLabelValues(lvs...), true}
26 | } else {
27 | return &histogram{enable: false}
28 | }
29 | }
30 |
31 | func (h *labeledHistogram) With(labels Labels) Histogram {
32 | if h.enable {
33 | return &histogram{h.HistogramVec.With(prometheus.Labels(labels)), true}
34 | } else {
35 | return &histogram{enable: false}
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/skunkworks/monitor/go-client/monitor/observer.go:
--------------------------------------------------------------------------------
1 | package monitor
2 |
3 | // Observe calls f(value). It implements Observer.
4 | func (f ObserverFunc) Observe(v float64) {
5 | f(v)
6 | }
7 |
--------------------------------------------------------------------------------
/skunkworks/monitor/go-client/monitor/summary.go:
--------------------------------------------------------------------------------
1 | package monitor
2 |
3 | import (
4 | "github.com/prometheus/client_golang/prometheus"
5 | )
6 |
7 | type summary struct {
8 | prometheus.Observer
9 | enable bool
10 | }
11 |
12 | func (s *summary) Observe(v float64) {
13 | if s.enable {
14 | s.Observer.Observe(v)
15 | }
16 | }
17 |
18 | type labeledSummary struct {
19 | *prometheus.SummaryVec
20 | enable bool
21 | }
22 |
23 | func (s *labeledSummary) WithLabelValues(lvs ...string) Summary {
24 | if s.enable {
25 | return &summary{s.SummaryVec.WithLabelValues(lvs...), true}
26 | } else {
27 | return &summary{enable: false}
28 | }
29 | }
30 |
31 | func (s *labeledSummary) With(labels Labels) Summary {
32 | if s.enable {
33 | return &summary{s.SummaryVec.With(prometheus.Labels(labels)), true}
34 | } else {
35 | return &summary{enable: false}
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/skunkworks/monitor/go-client/monitor/timer.go:
--------------------------------------------------------------------------------
1 | package monitor
2 |
3 | import (
4 | "github.com/prometheus/client_golang/prometheus"
5 | )
6 |
7 | type timer struct {
8 | *prometheus.Timer
9 | enable bool
10 | }
11 |
12 | func (t *timer) ObserveDuration() {
13 | if t.enable {
14 | t.Timer.ObserveDuration()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/skunkworks/util/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 | Copyright (c)
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
--------------------------------------------------------------------------------
/skunkworks/util/README.md:
--------------------------------------------------------------------------------
1 | # util
2 |
3 | 工具库
--------------------------------------------------------------------------------
/skunkworks/util/cas/doc.go:
--------------------------------------------------------------------------------
1 | // compare and swap util
2 | package cas
3 |
--------------------------------------------------------------------------------
/skunkworks/util/cas/mutex.go:
--------------------------------------------------------------------------------
1 | package cas
2 |
3 | import (
4 | "sync/atomic"
5 | "time"
6 | )
7 |
8 | const DefLoopTime = time.Millisecond * 5
9 |
10 | type Mutex struct {
11 | LoopTimeout time.Duration
12 | isLock int32
13 | }
14 |
15 | func (m *Mutex) Lock() {
16 | timeout := m.LoopTimeout
17 | if timeout <= 0 {
18 | timeout = DefLoopTime
19 | }
20 | for {
21 | if m.isLock == 0 && atomic.CompareAndSwapInt32(&m.isLock, 0, 1) {
22 | break
23 | }
24 | time.Sleep(timeout)
25 | }
26 | }
27 |
28 | func (m *Mutex) Unlock() {
29 | m.isLock = 0
30 | }
31 |
32 | // type RWMutex struct {
33 | // w Mutex // held if there are pending writers
34 | // writerSem uint32 // semaphore for writers to wait for completing readers
35 | // readerSem uint32 // semaphore for readers to wait for completing writers
36 | // readerCount int32 // number of pending readers
37 | // readerWait int32 // number of departing readers
38 | // }
39 |
40 | // func (m *RWMutex) Lock() {
41 | // m.w.Lock()
42 | // }
43 |
44 | // func (m *RWMutex) Unlock() {
45 |
46 | // }
47 |
48 | // func (m *RWMutex) RLock() {
49 |
50 | // }
51 |
52 | // func (m *RWMutex) RUnlock() {
53 |
54 | // }
55 |
--------------------------------------------------------------------------------
/skunkworks/util/id/id_test.go:
--------------------------------------------------------------------------------
1 | package id
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func Test_Id(t *testing.T) {
9 | fmt.Println("get one id:", Next())
10 | fmt.Println("get node seq:", NextSeq())
11 | }
12 |
13 | func Test_Node(t *testing.T) {
14 | fmt.Println("get node id:", GetNodeId())
15 | }
16 |
17 | func Test_Hostip(t *testing.T) {
18 | ip, _ := hostIP()
19 | fmt.Println("get host ip:", ip)
20 | fmt.Println("get host ip num:", ip2num(ip))
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/skunkworks/util/pacakge.go:
--------------------------------------------------------------------------------
1 | package util
2 |
--------------------------------------------------------------------------------
/skunkworks/util/workerpool/worker.go:
--------------------------------------------------------------------------------
1 | package workerpool
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | var (
8 | maxQueue = 200
9 | )
10 |
11 | // Worker represents the worker that executes the job
12 | type worker struct {
13 | workerPool *WorkerPool
14 | //as a lock for this job
15 | jobChannel chan Job
16 | quit chan bool
17 | id int
18 | }
19 |
20 | func newWorker(workerPool *WorkerPool) worker {
21 | return worker{
22 | workerPool: workerPool,
23 | jobChannel: make(chan Job),
24 | quit: make(chan bool),
25 | }
26 | }
27 |
28 | // Start method starts the run loop for the worker, listening for a quit channel in
29 | // case we need to stop it
30 | func (w worker) start() {
31 | go func() {
32 | for {
33 | // register the current worker into the worker queue.
34 | w.workerPool.jobPool <- w.jobChannel
35 |
36 | select {
37 | case job := <-w.jobChannel:
38 | // we have received a work request.
39 | if err := w.workerPool.handler(job.payload); err != nil {
40 | fmt.Printf("Error handling: %s", err.Error())
41 | }
42 |
43 | case <-w.quit:
44 | // we have received a signal to stop
45 | return
46 | }
47 | }
48 | }()
49 | }
50 |
51 | // Stop signals the worker to stop listening for work requests.
52 | func (w worker) stop() {
53 | go func() {
54 | w.quit <- true
55 | }()
56 | }
57 |
--------------------------------------------------------------------------------
/skunkworks/zap/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016-2017 Uber Technologies, Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/skunkworks/zap/buffer/pool.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package buffer
22 |
23 | import "sync"
24 |
25 | // A Pool is a type-safe wrapper around a sync.Pool.
26 | type Pool struct {
27 | p *sync.Pool
28 | }
29 |
30 | // NewPool constructs a new Pool.
31 | func NewPool() Pool {
32 | return Pool{p: &sync.Pool{
33 | New: func() interface{} {
34 | return &Buffer{bs: make([]byte, 0, _size)}
35 | },
36 | }}
37 | }
38 |
39 | // Get retrieves a Buffer from the pool, creating one if necessary.
40 | func (p Pool) Get() *Buffer {
41 | buf := p.p.Get().(*Buffer)
42 | buf.Reset()
43 | buf.pool = p
44 | return buf
45 | }
46 |
47 | func (p Pool) put(buf *Buffer) {
48 | p.p.Put(buf)
49 | }
50 |
--------------------------------------------------------------------------------
/skunkworks/zap/check_license.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | ERROR_COUNT=0
4 | while read -r file
5 | do
6 | case "$(head -1 "${file}")" in
7 | *"Copyright (c) "*" Uber Technologies, Inc.")
8 | # everything's cool
9 | ;;
10 | *)
11 | echo "$file is missing license header."
12 | (( ERROR_COUNT++ ))
13 | ;;
14 | esac
15 | done < <(git ls-files "*\.go")
16 |
17 | exit $ERROR_COUNT
18 |
--------------------------------------------------------------------------------
/skunkworks/zap/flag.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package zap
22 |
23 | import (
24 | "flag"
25 |
26 | "github.com/finogeeks/ligase/skunkworks/zap/zapcore"
27 | )
28 |
29 | // LevelFlag uses the standard library's flag.Var to declare a global flag
30 | // with the specified name, default, and usage guidance. The returned value is
31 | // a pointer to the value of the flag.
32 | //
33 | // If you don't want to use the flag package's global state, you can use any
34 | // non-nil *Level as a flag.Value with your own *flag.FlagSet.
35 | func LevelFlag(name string, defaultLevel zapcore.Level, usage string) *zapcore.Level {
36 | lvl := defaultLevel
37 | flag.Var(&lvl, name, usage)
38 | return &lvl
39 | }
40 |
--------------------------------------------------------------------------------
/skunkworks/zap/glide.yaml:
--------------------------------------------------------------------------------
1 | package: github.com/finogeeks/dendrite/skunkworks/zap
2 | license: MIT
3 | import:
4 | - package: go.uber.org/atomic
5 | version: ^1
6 | - package: go.uber.org/multierr
7 | version: ^1
8 | testImport:
9 | - package: github.com/satori/go.uuid
10 | - package: github.com/sirupsen/logrus
11 | - package: github.com/apex/log
12 | subpackages:
13 | - handlers/json
14 | - package: github.com/go-kit/kit
15 | subpackages:
16 | - log
17 | - package: github.com/stretchr/testify
18 | subpackages:
19 | - assert
20 | - require
21 | - package: gopkg.in/inconshreveable/log15.v2
22 | - package: github.com/mattn/goveralls
23 | - package: github.com/pborman/uuid
24 | - package: github.com/pkg/errors
25 | - package: go.pedge.io/lion
26 | - package: github.com/rs/zerolog
27 | - package: golang.org/x/tools
28 | subpackages:
29 | - cover
30 | - package: github.com/golang/lint
31 | subpackages:
32 | - golint
33 | - package: github.com/axw/gocov
34 | subpackages:
35 | - gocov
36 |
--------------------------------------------------------------------------------
/skunkworks/zap/internal/bufferpool/bufferpool.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | // Package bufferpool houses zap's shared internal buffer pool. Third-party
22 | // packages can recreate the same functionality with buffers.NewPool.
23 | package bufferpool
24 |
25 | import "github.com/finogeeks/ligase/skunkworks/zap/buffer"
26 |
27 | var (
28 | _pool = buffer.NewPool()
29 | // Get retrieves a buffer from the pool, creating one if necessary.
30 | Get = _pool.Get
31 | )
32 |
--------------------------------------------------------------------------------
/skunkworks/zap/internal/color/color.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | // Package color adds coloring functionality for TTY output.
22 | package color
23 |
24 | import "fmt"
25 |
26 | // Foreground colors.
27 | const (
28 | Black Color = iota + 30
29 | Red
30 | Green
31 | Yellow
32 | Blue
33 | Magenta
34 | Cyan
35 | White
36 | )
37 |
38 | // Color represents a text color.
39 | type Color uint8
40 |
41 | // Add adds the coloring to the given string.
42 | func (c Color) Add(s string) string {
43 | return fmt.Sprintf("\x1b[%dm%s\x1b[0m", uint8(c), s)
44 | }
45 |
--------------------------------------------------------------------------------
/skunkworks/zap/internal/color/color_test.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package color
22 |
23 | import (
24 | "testing"
25 |
26 | "github.com/stretchr/testify/assert"
27 | )
28 |
29 | func TestColorFormatting(t *testing.T) {
30 | assert.Equal(
31 | t,
32 | "\x1b[31mfoo\x1b[0m",
33 | Red.Add("foo"),
34 | "Unexpected colored output.",
35 | )
36 | }
37 |
--------------------------------------------------------------------------------
/skunkworks/zap/internal/exit/exit_test.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package exit
22 |
23 | import (
24 | "testing"
25 |
26 | "github.com/stretchr/testify/assert"
27 | )
28 |
29 | func TestStub(t *testing.T) {
30 | tests := []struct {
31 | f func()
32 | want bool
33 | }{
34 | {Exit, true},
35 | {func() {}, false},
36 | }
37 |
38 | for _, tt := range tests {
39 | s := WithStub(tt.f)
40 | assert.Equal(t, tt.want, s.Exited, "Stub captured unexpected exit value.")
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/skunkworks/zap/scripts/cover.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 | echo "" > cover.out
5 |
6 | for d in $(go list $@); do
7 | go test -race -coverprofile=profile.out $d
8 | if [ -f profile.out ]; then
9 | cat profile.out >> cover.out
10 | rm profile.out
11 | fi
12 | done
13 |
--------------------------------------------------------------------------------
/skunkworks/zap/time.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package zap
22 |
23 | import "time"
24 |
25 | func timeToMillis(t time.Time) int64 {
26 | return t.UnixNano() / int64(time.Millisecond)
27 | }
28 |
--------------------------------------------------------------------------------
/skunkworks/zap/time_test.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package zap
22 |
23 | import (
24 | "testing"
25 | "time"
26 |
27 | "github.com/stretchr/testify/assert"
28 | )
29 |
30 | func TestTimeToMillis(t *testing.T) {
31 | tests := []struct {
32 | t time.Time
33 | stamp int64
34 | }{
35 | {t: time.Unix(0, 0), stamp: 0},
36 | {t: time.Unix(1, 0), stamp: 1000},
37 | {t: time.Unix(1, int64(500*time.Millisecond)), stamp: 1500},
38 | }
39 | for _, tt := range tests {
40 | assert.Equal(t, tt.stamp, timeToMillis(tt.t), "Unexpected timestamp for time %v.", tt.t)
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/skunkworks/zap/zapcore/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | // Package zapcore defines and implements the low-level interfaces upon which
22 | // zap is built. By providing alternate implementations of these interfaces,
23 | // external packages can extend zap's capabilities.
24 | package zapcore // import "github.com/finogeeks/ligase/skunkworks/zap/zapcore"
25 |
--------------------------------------------------------------------------------
/skunkworks/zap/zapcore/level_strings_test.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package zapcore
22 |
23 | import (
24 | "testing"
25 |
26 | "github.com/stretchr/testify/assert"
27 | )
28 |
29 | func TestAllLevelsCoveredByLevelString(t *testing.T) {
30 | numLevels := int((_maxLevel - _minLevel) + 1)
31 |
32 | isComplete := func(m map[Level]string) bool {
33 | return len(m) == numLevels
34 | }
35 |
36 | assert.True(t, isComplete(_levelToLowercaseColorString), "Colored lowercase strings don't cover all levels.")
37 | assert.True(t, isComplete(_levelToCapitalColorString), "Colored capital strings don't cover all levels.")
38 | }
39 |
--------------------------------------------------------------------------------
/skunkworks/zap/zaptest/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2016 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | // Package zaptest provides low-level helpers for testing log output. These
22 | // utilities are helpful in zap's own unit tests, but any assertions using
23 | // them are strongly coupled to a single encoding.
24 | //
25 | // Most users should use github.com/finogeeks/dendrite/skunkworks/zap/zaptest/observer instead of this
26 | // package.
27 | package zaptest // import "github.com/finogeeks/ligase/skunkworks/zap/zaptest"
28 |
--------------------------------------------------------------------------------
/skunkworks/zap/zaptest/observer/logged_entry.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 Uber Technologies, Inc.
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in
11 | // all copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | // THE SOFTWARE.
20 |
21 | package observer
22 |
23 | import "github.com/finogeeks/ligase/skunkworks/zap/zapcore"
24 |
25 | // An LoggedEntry is an encoding-agnostic representation of a log message.
26 | // Field availability is context dependant.
27 | type LoggedEntry struct {
28 | zapcore.Entry
29 | Context []zapcore.Field
30 | }
31 |
32 | // ContextMap returns a map for all fields in Context.
33 | func (e LoggedEntry) ContextMap() map[string]interface{} {
34 | encoder := zapcore.NewMapObjectEncoder()
35 | for _, f := range e.Context {
36 | f.AddTo(encoder)
37 | }
38 | return encoder.Fields
39 | }
40 |
--------------------------------------------------------------------------------
/storage/implements/appservice/txn_id_counter_table.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 New Vector Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package appservice
19 |
20 | import (
21 | "context"
22 | "database/sql"
23 | )
24 |
25 | const txnIDSchema = `
26 | -- Keeps a count of the current transaction ID
27 | CREATE SEQUENCE IF NOT EXISTS txn_id_counter START 1;
28 | `
29 |
30 | const selectTxnIDSQL = "SELECT nextval('txn_id_counter')"
31 |
32 | type txnStatements struct {
33 | selectTxnIDStmt *sql.Stmt
34 | }
35 |
36 | func (s *txnStatements) prepare(db *sql.DB) (err error) {
37 | _, err = db.Exec(txnIDSchema)
38 | if err != nil {
39 | return
40 | }
41 |
42 | if s.selectTxnIDStmt, err = db.Prepare(selectTxnIDSQL); err != nil {
43 | return
44 | }
45 |
46 | return
47 | }
48 |
49 | // selectTxnID selects the latest ascending transaction ID
50 | func (s *txnStatements) selectTxnID(
51 | ctx context.Context,
52 | ) (txnID int, err error) {
53 | err = s.selectTxnIDStmt.QueryRowContext(ctx).Scan(&txnID)
54 | return
55 | }
56 |
--------------------------------------------------------------------------------
/storage/implements/init.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package implements
16 |
17 | import (
18 | _ "github.com/finogeeks/ligase/storage/implements/accounts"
19 | _ "github.com/finogeeks/ligase/storage/implements/appservice"
20 | _ "github.com/finogeeks/ligase/storage/implements/configdb"
21 | _ "github.com/finogeeks/ligase/storage/implements/devices"
22 | _ "github.com/finogeeks/ligase/storage/implements/encryptoapi"
23 | _ "github.com/finogeeks/ligase/storage/implements/keydb"
24 | _ "github.com/finogeeks/ligase/storage/implements/presence"
25 | _ "github.com/finogeeks/ligase/storage/implements/publicroomapi"
26 | _ "github.com/finogeeks/ligase/storage/implements/pushapi"
27 | _ "github.com/finogeeks/ligase/storage/implements/rcs_server"
28 | _ "github.com/finogeeks/ligase/storage/implements/roomserver"
29 | _ "github.com/finogeeks/ligase/storage/implements/syncapi"
30 | )
31 |
--------------------------------------------------------------------------------
/storage/implements/keydb/keyring.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 New Vector Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package keydb
19 |
20 | import "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
21 |
22 | // CreateKeyRing creates and configures a KeyRing object.
23 | //
24 | // It creates the necessary key fetchers and collects them into a KeyRing
25 | // backed by the given KeyDatabase.
26 | func CreateKeyRing(client gomatrixserverlib.Client,
27 | keyDB gomatrixserverlib.KeyDatabase) gomatrixserverlib.KeyRing {
28 | return gomatrixserverlib.KeyRing{
29 | KeyFetchers: []gomatrixserverlib.KeyFetcher{
30 | // TODO: Use perspective key fetchers for production.
31 | &gomatrixserverlib.DirectKeyFetcher{Client: client},
32 | },
33 | KeyDatabase: keyDB,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/storage/implements/publicroomapi/prepare.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package publicroomapi
19 |
20 | import (
21 | "database/sql"
22 | )
23 |
24 | // a statementList is a list of SQL statements to prepare and a pointer to where to store the resulting prepared statement.
25 | type statementList []struct {
26 | statement **sql.Stmt
27 | sql string
28 | }
29 |
30 | // prepare the SQL for each statement in the list and assign the result to the prepared statement.
31 | func (s statementList) prepare(db *sql.DB) (err error) {
32 | for _, statement := range s {
33 | if *statement.statement, err = db.Prepare(statement.sql); err != nil {
34 | return
35 | }
36 | }
37 | return
38 | }
39 |
--------------------------------------------------------------------------------
/storage/implements/rcs_server/prepare.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package rcs_server
16 |
17 | import "database/sql"
18 |
19 | // a statementList is a list of SQL statements to prepare and a pointer to where to store the resulting prepared statement.
20 | type statementList []struct {
21 | statement **sql.Stmt
22 | sql string
23 | }
24 |
25 | // prepare the SQL for each statement in the list and assign the result to the prepared statement.
26 | // nolint: safesql
27 | func (s statementList) prepare(db *sql.DB) (err error) {
28 | for _, statement := range s {
29 | if *statement.statement, err = db.Prepare(statement.sql); err != nil {
30 | return
31 | }
32 | }
33 | return
34 | }
35 |
--------------------------------------------------------------------------------
/storage/implements/rcs_server/sql.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package rcs_server
16 |
17 | import "database/sql"
18 |
19 | type statements struct {
20 | friendshipStatements
21 | }
22 |
23 | func (s *statements) prepare(db *sql.DB, d *Database) error {
24 | var err error
25 |
26 | for _, prepare := range []func(db *sql.DB, d *Database) error{
27 | s.friendshipStatements.prepare,
28 | } {
29 | if err = prepare(db, d); err != nil {
30 | return err
31 | }
32 | }
33 |
34 | return nil
35 | }
36 |
--------------------------------------------------------------------------------
/storage/implements/roomserver/prepare.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package roomserver
19 |
20 | import (
21 | "database/sql"
22 | )
23 |
24 | // a statementList is a list of SQL statements to prepare and a pointer to where to store the resulting prepared statement.
25 | type statementList []struct {
26 | statement **sql.Stmt
27 | sql string
28 | }
29 |
30 | // prepare the SQL for each statement in the list and assign the result to the prepared statement.
31 | // nolint: safesql
32 | func (s statementList) prepare(db *sql.DB) (err error) {
33 | for _, statement := range s {
34 | if *statement.statement, err = db.Prepare(statement.sql); err != nil {
35 | return
36 | }
37 | }
38 | return
39 | }
40 |
--------------------------------------------------------------------------------
/storage/implements/roomserver/sql.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Vector Creations Ltd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 | //
16 | // Modifications copyright (C) 2020 Finogeeks Co., Ltd
17 |
18 | package roomserver
19 |
20 | import (
21 | "database/sql"
22 | )
23 |
24 | type statements struct {
25 | roomStatements
26 | eventStatements
27 | eventJSONStatements
28 | stateSnapshotStatements
29 | roomAliasesStatements
30 | inviteStatements
31 | membershipStatements
32 | roomDomainsStatements
33 | settingsStatements
34 | }
35 |
36 | func (s *statements) prepare(db *sql.DB, d *Database) error {
37 | var err error
38 |
39 | for _, prepare := range []func(db *sql.DB, d *Database) error{
40 | s.roomStatements.prepare,
41 | s.eventStatements.prepare,
42 | s.eventJSONStatements.prepare,
43 | s.stateSnapshotStatements.prepare,
44 | s.roomAliasesStatements.prepare,
45 | s.inviteStatements.prepare,
46 | s.membershipStatements.prepare,
47 | s.roomDomainsStatements.prepare,
48 | s.settingsStatements.prepare,
49 | } {
50 | if err = prepare(db, d); err != nil {
51 | return err
52 | }
53 | }
54 |
55 | return nil
56 | }
57 |
--------------------------------------------------------------------------------
/storage/model/DBmonitor.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | mon "github.com/finogeeks/ligase/skunkworks/monitor/go-client/monitor"
19 | )
20 |
21 | type DBMonitor interface {
22 | SetGauge(gauge mon.LabeledGauge)
23 | // SetCounter(counter mon.LabeledCounter)
24 | // SetHistogram(histogram mon.LabeledHistogram)
25 | // SetSummary(summary mon.LabeledSummary)
26 | }
27 |
--------------------------------------------------------------------------------
/storage/model/configDB.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | "context"
19 | )
20 |
21 | type ConfigDatabase interface {
22 | UpsertServerName(ctx context.Context, nid int64, serverName string) error
23 | SelectServerNames(ctx context.Context) (results []string, err error)
24 | UpsertServerInstance(ctx context.Context, nid int64, serverName string) error
25 | SelectServerInstance(ctx context.Context, serverName string) (instance int64, err error)
26 | }
27 |
--------------------------------------------------------------------------------
/storage/model/keyDB.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | "context"
19 |
20 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
21 | )
22 |
23 | type KeyDatabase interface {
24 | //NewDatabase(driver, createAddr, address, topic string, useAsync bool) (interface{}, error)
25 |
26 | FetcherName() string
27 |
28 | FetchKeys(
29 | ctx context.Context,
30 | requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
31 | ) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error)
32 |
33 | StoreKeys(
34 | ctx context.Context,
35 | keyMap map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult,
36 | ) error
37 |
38 | InsertRootCA(ctx context.Context, rootCA string) error
39 | SelectAllCerts(ctx context.Context) (string, string, string, string, error)
40 | UpsertCert(ctx context.Context, serverCert, serverKey string) error
41 | UpsertCRL(ctx context.Context, CRL string) error
42 | }
43 |
--------------------------------------------------------------------------------
/storage/model/presenceDB.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package model
16 |
17 | import (
18 | "context"
19 | "github.com/finogeeks/ligase/model/dbtypes"
20 | )
21 |
22 | type PresenceDatabase interface {
23 | //NewDatabase(driver, createAddr, address, topic string, useAsync bool) (interface{}, error)
24 |
25 | WriteDBEvent(ctx context.Context, update *dbtypes.DBEvent) error
26 |
27 | RecoverCache()
28 |
29 | UpsertPresences(
30 | ctx context.Context, userID, status, statusMsg, extStatusMsg string,
31 | ) error
32 |
33 | OnUpsertPresences(
34 | ctx context.Context, userID, status, statusMsg, extStatusMsg string,
35 | ) error
36 | }
37 |
--------------------------------------------------------------------------------
/syncserver/extra/extra.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package extra
16 |
17 | import (
18 | "github.com/finogeeks/ligase/model/authtypes"
19 | "github.com/finogeeks/ligase/model/repos"
20 | "github.com/finogeeks/ligase/model/syncapitypes"
21 | "github.com/finogeeks/ligase/skunkworks/gomatrixserverlib"
22 | )
23 |
24 | func ExpandSyncData(repo *repos.RoomCurStateRepo, device *authtypes.Device, displayNameRepo *repos.DisplayNameRepo, res *syncapitypes.SyncServerResponse) {
25 | ExpandHints(repo, device, displayNameRepo, res)
26 | }
27 |
28 | func ExpandMessages(event *gomatrixserverlib.ClientEvent, userID string, repo *repos.RoomCurStateRepo, displayNameRepo *repos.DisplayNameRepo) {
29 | device := &authtypes.Device{
30 | UserID: userID,
31 | IsHuman: true,
32 | }
33 | ExpandEventHint(event, device, repo, displayNameRepo)
34 | }
35 |
--------------------------------------------------------------------------------
/tokenrewrite/storage/devices_table.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package storage
16 |
17 | import (
18 | "context"
19 | "database/sql"
20 | )
21 |
22 | const upsertDeviceSQL = "" +
23 | "INSERT INTO devices(user_id,device_id,display_name) VALUES ($1, $2, $3)" +
24 | " ON CONFLICT DO NOTHING"
25 |
26 | type devicesStatements struct {
27 | upsetDeviceStmt *sql.Stmt
28 | }
29 |
30 | func (s *devicesStatements) prepare(db *sql.DB) (err error) {
31 | if s.upsetDeviceStmt, err = db.Prepare(upsertDeviceSQL); err != nil {
32 | return
33 | }
34 | return
35 | }
36 |
37 | func (s *devicesStatements) upsertDevice(
38 | ctx context.Context, userID, deviceID, displayName string,
39 | ) error {
40 | _, err := s.upsetDeviceStmt.ExecContext(ctx, userID, deviceID, displayName)
41 | return err
42 | }
43 |
--------------------------------------------------------------------------------
/tokenrewrite/storage/tokens_table.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package storage
16 |
17 | import (
18 | "context"
19 | "database/sql"
20 | )
21 |
22 | const upsertTokenSQL = "" +
23 | "INSERT INTO access_tokens(id, user_id, device_id, token) VALUES ($1, $2, $3, $4)" +
24 | " ON CONFLICT DO NOTHING"
25 |
26 | type tokensStatements struct {
27 | upsetTokenStmt *sql.Stmt
28 | }
29 |
30 | func (s *tokensStatements) prepare(db *sql.DB) (err error) {
31 | if s.upsetTokenStmt, err = db.Prepare(upsertTokenSQL); err != nil {
32 | return
33 | }
34 | return
35 | }
36 |
37 | func (s *tokensStatements) upsertToken(
38 | ctx context.Context, id int64, userID, deviceID, token string,
39 | ) error {
40 | _, err := s.upsetTokenStmt.ExecContext(ctx, id, userID, deviceID, token)
41 | return err
42 | }
43 |
--------------------------------------------------------------------------------
/tokenrewrite/storage/users_table.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package storage
16 |
17 | import (
18 | "context"
19 | "database/sql"
20 | )
21 |
22 | const upsertUserSQL = "" +
23 | "INSERT INTO users(name) VALUES ($1)" +
24 | " ON CONFLICT DO NOTHING"
25 |
26 | type usersStatements struct {
27 | upsetUserStmt *sql.Stmt
28 | }
29 |
30 | func (s *usersStatements) prepare(db *sql.DB) (err error) {
31 | if s.upsetUserStmt, err = db.Prepare(upsertUserSQL); err != nil {
32 | return
33 | }
34 | return
35 | }
36 |
37 | func (s *usersStatements) upsertUser(
38 | ctx context.Context, userID string,
39 | ) error {
40 | _, err := s.upsetUserStmt.ExecContext(ctx, userID)
41 | return err
42 | }
43 |
--------------------------------------------------------------------------------
/tokenrewrite/tokenrewrite.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Finogeeks Co., Ltd
2 | //
3 | // This program is free software: you can redistribute it and/or modify
4 | // it under the terms of the GNU Affero General Public License, version 3,
5 | // as published by the Free Software Foundation.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Affero General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Affero General Public License
13 | // along with this program. If not, see .
14 |
15 | package tokenrewrite
16 |
17 | import (
18 | "github.com/finogeeks/ligase/common"
19 | "github.com/finogeeks/ligase/common/config"
20 | "github.com/finogeeks/ligase/tokenrewrite/rpc"
21 | )
22 |
23 | func SetupTokenRewrite(
24 | rpcClient *common.RpcClient,
25 | cfg *config.Dendrite,
26 | ) {
27 | tokenRpcConsumer := rpc.NewTokenRpcConsumer(rpcClient, cfg)
28 | tokenRpcConsumer.Start()
29 | }
30 |
--------------------------------------------------------------------------------