Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi committed Nov 29, 2018
1 parent ae472fe commit 504a207
Show file tree
Hide file tree
Showing 6,941 changed files with 3,229,930 additions and 1 deletion.
The diff you're trying to view is too large. We only load the first 3000 changed files.
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#folder
target/
.vagrant/

#fixed file
.class
.exe
.log
.prefs
.classpath
.metadata
.settings
.DS_Store
Thumbs.db
.project
*.iml
*.ipr
*.iws
*.tar.gz
*.bak
.idea
*.log
*.swp
*.swo
access/session/session
access/frontend/frontend
access/auth_key/auth_key
messenger/biz_server/biz_server
messenger/sync/sync
messenger/upload/upload
service/status/status
service/idgen/idgen/idgen
service/auth_session/auth_session
service/document/document
tools/daeml/daeml

nebula-dal-generator

service/auth_session/biz/dal/dalgen/nebula-dal-generator
service/document/biz/dal/dalgen/nebula-dal-generator
messenger/sync/biz/dal/dalgen/nebula-dal-generator
messenger/biz_server/biz/dal/dalgen/nebula-dal-generator
messenger/sync/biz/dal/dalgen/nebula-dal-generator
messenger/sync/biz/dal/dalgen/nebula-dal-generator
messenger/biz_server/biz/dal/dalgen/nebula-dal-generator
123 changes: 122 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,122 @@
# chatengine
# NebulaChat - Open source [mtproto](https://core.telegram.org/mtproto) server written in golang
> 打造高性能、稳定并且功能完善的开源mtproto服务端,建设开源telegram客户端生态系统非官方首选服务!
## Chinese

### 简介
Open source [mtproto](https://core.telegram.org/mtproto) server written in golang

### 架构图
![架构图](doc/image/architecture-001.jpeg)

### 文档
[Diffie–Hellman key exchange](doc/dh-key-exchange.md)

[Creating an Authorization Key](doc/Creating_an_Authorization_Key.md)

[Mobile Protocol: Detailed Description (v.1.0, DEPRECATED)](doc/Mobile_Protocol-Detailed_Description_v.1.0_DEPRECATED.md)

[Encrypted CDNs for Speed and Security](doc/cdn.md) [@steedfly](https://github.com/steedfly)翻译

### 编译和安装
#### 简单安装
- 准备
```
mkdir $GOPATH/src/github.com/nebula-chat/
cd $GOPATH/src/github.com/nebula-chat/
git clone https://github.com/nebula-chat/chatengine.git
```
- 编译代码
```
编译frontend
cd $GOPATH/src/github.com/nebula-chat/chatengine/access/frontend
go build
编译auth_key
cd $GOPATH/src/github.com/nebula-chat/chatengine/access/auth_key
go build
编译auth_session
cd $GOPATH/src/github.com/nebula-chat/chatengine/service/auth_session
go build
编译sync
cd $GOPATH/src/github.com/nebula-chat/chatengine/messenger/sync
go build
编译upload
cd $GOPATH/src/github.com/nebula-chat/chatengine/messenger/upload
go build
编译document
cd $GOPATH/src/github.com/nebula-chat/chatengine/service/document
go build
编译biz_server
cd $GOPATH/src/github.com/nebula-chat/chatengine/messenger/biz_server
go build
编译session
cd $GOPATH/src/github.com/nebula-chat/chatengine/access/session
go build
```
- 运行
```
cd $GOPATH/src/github.comnebula-chat/chatengine/service/auth_session
./auth_session
cd $GOPATH/src/github.com/nebula-chat/chatengine/service/document
./document
cd $GOPATH/src/github.com/nebula-chat/chatengine/messenger/sync
./sync
cd $GOPATH/src/github.com/nebula-chat/chatengine/messenger/upload
./upload
cd $GOPATH/src/github.com/nebula-chat/chatengine/messenger/biz_server
./biz_server
cd $GOPATH/src/github.com/nebula-chat/chatengine/access/auth_key
./auth_key
cd $GOPATH/src/github.com/nebula-chat/chatengine/access/session
./session
cd $GOPATH/src/github.com/nebula-chat/chatengine/access/frontend
./frontend
```
#### 更多文档
[Build document](doc/build.md)
[Build script](scripts/build.sh)
[Prerequisite script](scripts/prerequisite.sh)
### TODO
- Secret Chats
- bots
- payments
### 技术交流群
Bug反馈,意见和建议欢迎加入[Telegramd中文技术交流群](https://t.me/joinchat/D8b0DQ-CrvZXZv2dWn310g)讨论。
## English
### Introduce
open source mtproto server implement by golang, which compatible telegram client.
### Install
[Build and install](doc/build.md)
[build](scripts/build.sh)
[prerequisite](scripts/prerequisite.sh)
## Feedback
Please report bugs, concerns, suggestions by issues, or join telegram group [Telegramd](https://t.me/joinchat/D8b0DRJiuH8EcIHNZQmCxQ) to discuss problems around source code.
Empty file added access/READMD.md
Empty file.
10 changes: 10 additions & 0 deletions access/auth_key/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# auth_key server
## 为什么要独立出auth_key
> 从安全性考虑,除了auth_key之外,无任何系统可以直接访问auth_key数据库,部署时可以物理隔离,保证数据库的安全
## 功能
- handshake
> 生成auth_key
- query_auth_key
> 提供查询auth_key服务,仅session有权限访问
36 changes: 36 additions & 0 deletions access/auth_key/auth_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2018-present, NebulaChat Studio (https://nebula.chat).
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Author: Benqi ([email protected])

package main

import (
"flag"
"github.com/nebula-chat/chatengine/pkg/util"
"github.com/nebula-chat/chatengine/access/auth_key/server"
)

func init() {
flag.Set("alsologtostderr", "true")
flag.Set("log_dir", "false")
}

func main() {
flag.Parse()

instance := server.NewAuthKeyServer()
util.DoMainAppInstance(instance)
}
22 changes: 22 additions & 0 deletions access/auth_key/auth_key.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# auth_key.toml

ver = "0.0.1"
serverId = 1

[server.server]
name = "handshake"
protoName = "brpc"
addr = "0.0.0.0:10005"

[authSessionRpcClient]
serviceName = "auth_session"
etcdAddrs = ["http://127.0.0.1:2379"]
balancer = "round_robin"

[server.discovery]
serviceName = "handshake"
nodeID = "node1"
rPCAddr = "127.0.0.1:10005"
etcdAddrs = ["http://127.0.0.1:2379"]
interval = "2s"
tTL = "10s"
85 changes: 85 additions & 0 deletions access/auth_key/server/cache_state_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2018, https://github.com/nebulaim
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// salt cache
package server

import (
"fmt"
"time"
"github.com/golang/glog"
"github.com/nebula-chat/chatengine/mtproto"
"github.com/nebula-chat/chatengine/pkg/cache"
"encoding/hex"
)

const (
kSaltTimeout = 30 * 60 // salt timeout
// kCacheConfig = `{"conn":":"127.0.0.1:6039"}`
kAdapterName = "memory"
kCacheConfig = `{"interval":60}`
kCacheSaltPrefix = "salts"
)

var cacheStates *cacheStateManager = nil

func init() {
// rand.Seed(time.Now().UnixNano())
initCacheStateManager(kAdapterName, kCacheConfig)
}

type cacheStateManager struct {
cache cache.Cache
timeout time.Duration // salt timeout
}

func initCacheStateManager(name, config string) error {
if config == "" {
config = kCacheConfig
}

c, err := cache.NewCache(name, kCacheConfig)
if err != nil {
glog.Error(err)
return err
}

cacheStates = &cacheStateManager{cache: c, timeout: kSaltTimeout}
return nil
}

func genCacheStateKey(nonce, serverNonce []byte) string {
return fmt.Sprintf("%s_%s@%s", kCacheSaltPrefix, hex.EncodeToString(nonce), hex.EncodeToString(serverNonce))
}

func PutCacheState(nonce, serverNonce []byte, state *mtproto.HandshakeContext_Data) (error) {
k := genCacheStateKey(nonce, serverNonce)
glog.Info("put state key: (", k, ")")
return cacheStates.cache.Put(genCacheStateKey(nonce, serverNonce), state, time.Duration(5*time.Second))
}

func GetCacheState(nonce, serverNonce []byte) (state *mtproto.HandshakeContext_Data) {
k := genCacheStateKey(nonce, serverNonce)
glog.Info("get state key: (", k, ")")
v := cacheStates.cache.Get(genCacheStateKey(nonce, serverNonce))
if v != nil {
state = v.(*mtproto.HandshakeContext_Data)
} else {
glog.Warning("not found state by: (", k, ")")
}
return
}
51 changes: 51 additions & 0 deletions access/auth_key/server/conf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2018-present, NebulaChat Studio (https://nebula.chat).
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Author: Benqi ([email protected])

package server

import (
"flag"
"fmt"
"github.com/BurntSushi/toml"
"github.com/nebula-chat/chatengine/mtproto/rpc"
"github.com/nebula-chat/chatengine/pkg/grpc_util/service_discovery"
)

var (
confPath string
Conf *authKeyConfig
)

type authKeyConfig struct {
ServerId int32 // 服务器ID
// Mysql []mysql_client.MySQLConfig
Server *zrpc.ZRpcServerConfig
AuthSessionRpcClient service_discovery.ServiceDiscoveryClientConfig
// RpcServer *grpc_util.RPCServerConfig
}

func init() {
flag.StringVar(&confPath, "conf", "./auth_key.toml", "config path")
}

func InitializeConfig() (err error) {
_, err = toml.DecodeFile(confPath, &Conf)
if err != nil {
err = fmt.Errorf("decode file %s error: %v", confPath, err)
}
return
}
Loading

0 comments on commit 504a207

Please sign in to comment.