Skip to content

Commit

Permalink
Split nbfs to upload and document, fix upload big file bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi committed Jul 28, 2018
1 parent 20cc657 commit 570bc56
Show file tree
Hide file tree
Showing 95 changed files with 2,272 additions and 2,357 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ Go语言非官方开源telegram服务端,包括但不限于如下一些特色
go get
go build
编译session
cd $GOPATH/src/github.com/nebulaim/telegramd/server/access/session
go get
go build
编译auth_key
cd $GOPATH/src/github.com/nebulaim/telegramd/server/access/auth_key
go get
Expand All @@ -57,44 +52,49 @@ Go语言非官方开源telegram服务端,包括但不限于如下一些特色
go get
go build
编译nbfs
cd $GOPATH/src/github.com/nebulaim/telegramd/server/nbfs
编译upload
cd $GOPATH/src/github.com/nebulaim/telegramd/server/upload
go get
go build
编译document
cd $GOPATH/src/github.com/nebulaim/telegramd/service/document
go get
go build
编译biz_server
cd $GOPATH/src/github.com/nebulaim/telegramd/server/biz_server
go get
go build
编译session
cd $GOPATH/src/github.com/nebulaim/telegramd/server/access/session
go get
go build
```
- 运行
```
cd $GOPATH/src/github.com/nebulaim/telegramd/server/access/frontend
./frontend
cd $GOPATH/src/github.com/nebulaim/telegramd/server/access/auth_key
./auth_key
cd $GOPATH/src/github.com/nebulaim/telegramd/server/sync
./sync
cd $GOPATH/src/github.com/nebulaim/telegramd/server/nbfs
mkdir /opt/nbfs/0
mkdir /opt/nbfs/s
mkdir /opt/nbfs/m
mkdir /opt/nbfs/x
mkdir /opt/nbfs/y
mkdir /opt/nbfs/a
mkdir /opt/nbfs/b
mkdir /opt/nbfs/c
./nbfs
cd $GOPATH/src/github.com/nebulaim/telegramd/server/upload
./upload
cd $GOPATH/src/github.com/nebulaim/telegramd/service/document
./document
cd $GOPATH/src/github.com/nebulaim/telegramd/server/biz_server
./biz_server
cd $GOPATH/src/github.com/nebulaim/telegramd/server/access/session
./session
cd $GOPATH/src/github.com/nebulaim/telegramd/server/access/frontend
./frontend
```
#### 更多文档
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,33 @@
* limitations under the License.
*/

package file
package crypto

// inputFileLocation#14637196 volume_id:long local_id:int secret:long = InputFileLocation;
// inputEncryptedFileLocation#f5235d55 id:long access_hash:long = InputFileLocation;
// inputDocumentFileLocation#430f0724 id:long access_hash:long version:int = InputFileLocation;
import (
"github.com/golang/glog"
"crypto/md5"
"fmt"
"os"
"io"
)

// fileLocationUnavailable#7c596b46 volume_id:long local_id:int secret:long = FileLocation;
// fileLocation#53d69076 dc_id:int volume_id:long local_id:int secret:long = FileLocation;
// TODO(@benqi): remove to baselib
func CalcMd5File(filename string) (string, error) {
// fileName := core.NBFS_DATA_PATH + m.data.FilePath
f, err := os.Open(filename)
if err != nil {
glog.Error(err)
return "", err
}

defer f.Close()

md5Hash := md5.New()
if _, err := io.Copy(md5Hash, f); err != nil {
// fmt.Println("Copy", err)
glog.Error("Copy - ", err)
return "", err
}

return fmt.Sprintf("%x", md5Hash.Sum(nil)), nil
}
4 changes: 2 additions & 2 deletions baselib/grpc_util/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (c *RPCClient) Invoke(rpcMetaData *RpcMetadata, object mtproto.TLObject) (m
// return nil, err
}

glog.Infof("Invoke - method: {%s}, req: {%v}", t.Method, object)
glog.Infof("Invoke - method: {%s}", t.Method)
r := t.NewReplyFunc()
glog.Infof("Invoke - NewReplyFunc: {%v}, t: {%v}", r, reflect.TypeOf(r))

Expand Down Expand Up @@ -140,7 +140,7 @@ func (c *RPCClient) Invoke(rpcMetaData *RpcMetadata, object mtproto.TLObject) (m
}
return nil, mtproto.NewRpcError(int32(mtproto.TLRpcErrorCodes_INTERNAL), "INTERNAL_SERVER_ERROR")
} else {
glog.Infof("Invoke - Invoke reply: {%v}\n", r)
// glog.Infof("Invoke - Invoke reply: {%v}\n", r)
reply, ok := r.(mtproto.TLObject)

glog.Infof("Invoke %s time: %d", t.Method, (time.Now().Unix() - rpcMetaData.ReceiveTime))
Expand Down
2 changes: 1 addition & 1 deletion baselib/net2/tcp_client_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (cgm *TcpClientGroupManager) SendDataToAddress(name, address string, msg in

cgm.clientMapLock.RUnlock()

glog.Info("tcp_client_group_manager sendDataToAddress: {name: %s, conn: %s, msg: {%v}}", name, c, msg)
glog.Infof("tcp_client_group_manager sendDataToAddress: {name: %s, conn: %s, msg: {%v}}", name, c, msg)
return c.Send(msg)
}

Expand Down
8 changes: 4 additions & 4 deletions biz/core/photo/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package photo
import (
"github.com/nebulaim/telegramd/biz/core"
"github.com/nebulaim/telegramd/proto/mtproto"
"github.com/nebulaim/telegramd/server/nbfs/nbfs_client"
"github.com/nebulaim/telegramd/service/document/client"
"time"
)

Expand All @@ -39,7 +39,7 @@ func (m *PhotoModel) GetUserProfilePhoto(photoId int64) (photo *mtproto.UserProf
if photoId == 0 {
photo = mtproto.NewTLUserProfilePhotoEmpty().To_UserProfilePhoto()
} else {
sizes, _ := nbfs_client.GetPhotoSizeList(photoId)
sizes, _ := document_client.GetPhotoSizeList(photoId)
photo = MakeUserProfilePhoto(photoId, sizes)
}

Expand All @@ -50,7 +50,7 @@ func (m *PhotoModel) GetChatPhoto(photoId int64) (photo *mtproto.ChatPhoto) {
if photoId == 0 {
photo = mtproto.NewTLChatPhotoEmpty().To_ChatPhoto()
} else {
sizes, _ := nbfs_client.GetPhotoSizeList(photoId)
sizes, _ := document_client.GetPhotoSizeList(photoId)
photo = MakeChatPhoto(sizes)
}

Expand All @@ -61,7 +61,7 @@ func (m *PhotoModel) GetPhoto(photoId int64) (photo *mtproto.Photo) {
if photoId == 0 {
photo = mtproto.NewTLPhotoEmpty().To_Photo()
} else {
sizes, _ := nbfs_client.GetPhotoSizeList(photoId)
sizes, _ := document_client.GetPhotoSizeList(photoId)
if len(sizes) == 0 {
photo = mtproto.NewTLPhotoEmpty().To_Photo()
} else {
Expand Down
29 changes: 16 additions & 13 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ if password is empty ignore this section otherwise add password to the following
```
$ $GOPATH/src/github.com/nebulaim/telegramd/server/access/auth_key/auth_key.toml
$ $GOPATH/src/github.com/nebulaim/telegramd/server/sync/sync.toml
$ $GOPATH/src/github.com/nebulaim/telegramd/server/nbfs/nbfs.toml
$ $GOPATH/src/github.com/nebulaim/telegramd/server/upload/upload.toml
$ $GOPATH/src/github.com/nebulaim/telegramd/service/ocument/document.toml
$ $GOPATH/src/github.com/nebulaim/telegramd/server/biz_server/biz_server.toml
```
set ***my-secret-pw*** in mysql dsn as follow:
Expand Down Expand Up @@ -134,9 +135,16 @@ $ go get
$ go build
```

### build nbfs
### build upload
```
$ cd $GOPATH/src/github.com/nebulaim/telegramd/server/nbfs
$ cd $GOPATH/src/github.com/nebulaim/telegramd/server/upload
$ go get
$ go build
```

### build document
```
$ cd $GOPATH/src/github.com/nebulaim/telegramd/service/document
$ go get
$ go build
```
Expand Down Expand Up @@ -178,16 +186,11 @@ $ ./auth_key
$ cd $GOPATH/src/github.com/nebulaim/telegramd/server/sync
$ ./sync
$ cd $GOPATH/src/github.com/nebulaim/telegramd/server/nbfs
$ mkdir /opt/nbfs/0
$ mkdir /opt/nbfs/s
$ mkdir /opt/nbfs/m
$ mkdir /opt/nbfs/x
$ mkdir /opt/nbfs/y
$ mkdir /opt/nbfs/a
$ mkdir /opt/nbfs/b
$ mkdir /opt/nbfs/c
$ ./nbfs
$ cd $GOPATH/src/github.com/nebulaim/telegramd/server/upload
$ ./upload
$ cd $GOPATH/src/github.com/nebulaim/telegramd/service/document
$ ./document
$ cd $GOPATH/src/github.com/nebulaim/telegramd/server/biz_server
$ ./biz_server
Expand Down
4 changes: 2 additions & 2 deletions proto/mtproto/mtproto_http_proxy_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ func (c *MTProtoHttpProxyCodec) Send(msg interface{}) error {
"Access-Control-Allow-Origin": {"*"},
"Access-Control-Max-Age": {"1728000"},
"Cache-control": {"no-store"},
"Connection": {"close"},
"Connection": {"keep-alive"},
"Content-type": {"application/octet-stream"},
"Pragma": {"no-cache"},
"Strict-Transport-Security": {"max-age=15768000"},
},
ContentLength: int64(len(b)),
Body: ioutil.NopCloser(bytes.NewReader(b)),
Close: true,
Close: false,
}

err := rsp.Write(c.conn)
Expand Down
12 changes: 9 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ go get
go build
./sync &

echo "build nbfs ..."
cd ${telegramd}/server/nbfs
echo "build upload ..."
cd ${telegramd}/server/upload
go get
go build
./nbfs &
./upload &

echo "build document ..."
cd ${telegramd}/server/document
go get
go build
./document &

echo "build biz_server ..."
cd ${telegramd}/server/biz_server
Expand Down
9 changes: 7 additions & 2 deletions server/access/auth_key/server/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/nebulaim/telegramd/server/access/auth_key/dal/dataobject"
"math/big"
"time"
"github.com/nebulaim/telegramd/baselib/bytes2"
)

const (
Expand Down Expand Up @@ -251,14 +252,18 @@ func (s *handshake) onReq_DHParams(state *zproto.HandshakeState, request *mtprot
// 客户端传输数据解析
// check Nonce
if !bytes.Equal(request.Nonce, authKeyMD.Nonce) {
err = fmt.Errorf("onReq_DHParams - Invalid Nonce")
err = fmt.Errorf("onReq_DHParams - Invalid Nonce, req: %s, back: %s",
bytes2.HexDump(request.Nonce),
bytes2.HexDump(authKeyMD.Nonce))
glog.Error(err)
return nil, err
}

// check ServerNonce
if !bytes.Equal(request.ServerNonce, authKeyMD.ServerNonce) {
err = fmt.Errorf("onReq_DHParams - Wrong ServerNonce")
err = fmt.Errorf("onReq_DHParams - Wrong ServerNonce, req: %s, back: %s",
bytes2.HexDump(request.ServerNonce),
bytes2.HexDump(authKeyMD.ServerNonce))
glog.Error(err)
return nil, err
}
Expand Down
11 changes: 6 additions & 5 deletions server/access/session/server/client_session_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/nebulaim/telegramd/proto/zproto"
"math/rand"
"time"
"reflect"
)

const (
Expand Down Expand Up @@ -457,7 +458,7 @@ func (c *clientSessionHandler) onMessageData(connID ClientConnID, md *zproto.ZPr
)

for _, message := range messages {
glog.Info("onMessageData - ", message)
// glog.Info("onMessageData - ", message)

if message.Object == nil {
continue
Expand Down Expand Up @@ -1055,25 +1056,25 @@ func (c *clientSessionHandler) onInvokeAfterMsgsExt(connID ClientConnID, md *zpr
}

func (c *clientSessionHandler) onInvokeWithoutUpdatesExt(connID ClientConnID, md *zproto.ZProtoMetadata, msgId int64, seqNo int32, request *TLInvokeWithoutUpdatesExt) bool {
glog.Infof("onInvokeWithoutUpdatesExt - request data: {sess: %s, conn_id: %s, md: %s, msg_id: %d, seq_no: %d, request: {%v}}",
glog.Infof("onInvokeWithoutUpdatesExt - request data: {sess: %s, conn_id: %s, md: %s, msg_id: %d, seq_no: %d, request: {%s}}",
c,
connID,
md,
msgId,
seqNo,
request)
reflect.TypeOf(request))

return c.onRpcRequest(connID, md, msgId, seqNo, request.Query)
}

func (c *clientSessionHandler) onRpcRequest(connID ClientConnID, md *zproto.ZProtoMetadata, msgId int64, seqNo int32, object mtproto.TLObject) bool {
glog.Infof("onInvokeWithoutUpdatesExt - request data: {sess: %s, conn_id: %s, md: %s, msg_id: %d, seq_no: %d, request: {%v}}",
glog.Infof("onRpcRequest - request data: {sess: %s, conn_id: %s, md: %s, msg_id: %d, seq_no: %d, request: {%s}}",
c,
connID,
md,
msgId,
seqNo,
object)
reflect.TypeOf(object))

// TODO(@benqi): sync AuthUserId??
requestMessage := &mtproto.TLMessage2{
Expand Down
6 changes: 3 additions & 3 deletions server/access/session/server/client_session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (s *clientSessionManager) onRpcRequest(requests *rpcApiMessages) {
// err.(*mtproto.TLRpcError)

} else {
glog.Infof("OnMessage - rpc_result: {%v}\n", rpcResult)
// glog.Infof("OnMessage - rpc_result: {%v}\n", rpcResult)
reply.Result = rpcResult
}

Expand Down Expand Up @@ -546,7 +546,7 @@ func extractClientMessage(msgId int64, seqNo int32, object mtproto.TLObject, mes
//

for _, m := range msgContainer.Messages {
glog.Info("processMsgContainer - request data: ", m)
// glog.Info("processMsgContainer - request data: ", m)
if m.Object == nil {
continue
}
Expand Down Expand Up @@ -639,7 +639,7 @@ func extractClientMessage(msgId int64, seqNo int32, object mtproto.TLObject, mes
messages.messages = append(messages.messages, &mtproto.TLMessage2{MsgId: msgId, Seqno: seqNo, Object: invokeWithoutUpdatesExt})

default:
glog.Info("processOthers - request data: ", object)
// glog.Info("processOthers - request data: ", object)
messages.messages = append(messages.messages, &mtproto.TLMessage2{MsgId: msgId, Seqno: seqNo, Object: object})
}
}
2 changes: 1 addition & 1 deletion server/access/session/session.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ etcdAddrs = ["http://127.0.0.1:2379"]
balancer = "round_robin"

[nbfsRpcClient]
serviceName = "nbfs"
serviceName = "upload"
etcdAddrs = ["http://127.0.0.1:2379"]
balancer = "round_robin"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/nebulaim/telegramd/baselib/grpc_util"
"github.com/nebulaim/telegramd/baselib/logger"
"github.com/nebulaim/telegramd/proto/mtproto"
"github.com/nebulaim/telegramd/server/nbfs/nbfs_client"
"github.com/nebulaim/telegramd/service/document/client"
"golang.org/x/net/context"
)

Expand All @@ -44,7 +44,7 @@ func (s *AccountServiceImpl) AccountGetWallPapers(ctx context.Context, request *

for _, wallData := range wallDataList {
if wallData.Type == 0 {
szList, _ := nbfs_client.GetPhotoSizeList(wallData.PhotoId)
szList, _ := document_client.GetPhotoSizeList(wallData.PhotoId)
wall := &mtproto.TLWallPaper{Data2: &mtproto.WallPaper_Data{
Id: wallData.Id,
Title: wallData.Title,
Expand Down
Loading

0 comments on commit 570bc56

Please sign in to comment.