Просмотр исходного кода

Remove borsh borsh new borsch

tags/0.9
9seconds 7 лет назад
Родитель
Сommit
d3e685de97

+ 21
- 0
mtproto/rpc/handshake_request.go Просмотреть файл

1
+package rpc
2
+
3
+import "bytes"
4
+
5
+type HandshakeRequest struct {
6
+}
7
+
8
+func (r *HandshakeRequest) Bytes() []byte {
9
+	buf := &bytes.Buffer{}
10
+
11
+	buf.Write(TagHandshake)
12
+	buf.Write(HandshakeFlags)
13
+	buf.Write(HandshakeSenderPID)
14
+	buf.Write(HandshakePeerPID)
15
+
16
+	return buf.Bytes()
17
+}
18
+
19
+func NewHandshakeRequest() *HandshakeRequest {
20
+	return &HandshakeRequest{}
21
+}

mtproto/rpc/rpc_handshake_response.go → mtproto/rpc/handshake_response.go Просмотреть файл

6
 	"github.com/juju/errors"
6
 	"github.com/juju/errors"
7
 )
7
 )
8
 
8
 
9
-type RPCHandshakeResponse struct {
9
+type HandshakeResponse struct {
10
 	Type      []byte
10
 	Type      []byte
11
 	Flags     []byte
11
 	Flags     []byte
12
 	SenderPID []byte
12
 	SenderPID []byte
13
 	PeerPID   []byte
13
 	PeerPID   []byte
14
 }
14
 }
15
 
15
 
16
-func (r *RPCHandshakeResponse) Bytes() []byte {
16
+func (r *HandshakeResponse) Bytes() []byte {
17
 	buf := &bytes.Buffer{}
17
 	buf := &bytes.Buffer{}
18
 
18
 
19
 	buf.Write(r.Type[:])
19
 	buf.Write(r.Type[:])
24
 	return buf.Bytes()
24
 	return buf.Bytes()
25
 }
25
 }
26
 
26
 
27
-func (r *RPCHandshakeResponse) Valid(req *RPCHandshakeRequest) error {
28
-	if !bytes.Equal(r.Type, RPCTagHandshake) {
27
+func (r *HandshakeResponse) Valid(req *HandshakeRequest) error {
28
+	if !bytes.Equal(r.Type, TagHandshake) {
29
 		return errors.New("Unexpected handshake tag")
29
 		return errors.New("Unexpected handshake tag")
30
 	}
30
 	}
31
-	if !bytes.Equal(r.PeerPID, RPCHandshakeSenderPID) {
31
+	if !bytes.Equal(r.PeerPID, HandshakeSenderPID) {
32
 		return errors.New("Incorrect sender PID")
32
 		return errors.New("Incorrect sender PID")
33
 	}
33
 	}
34
 
34
 
35
 	return nil
35
 	return nil
36
 }
36
 }
37
 
37
 
38
-func NewRPCHandshakeResponse(data []byte) (*RPCHandshakeResponse, error) {
38
+func NewHandshakeResponse(data []byte) (*HandshakeResponse, error) {
39
 	if len(data) != 32 {
39
 	if len(data) != 32 {
40
 		return nil, errors.New("Incorrect handshake response length")
40
 		return nil, errors.New("Incorrect handshake response length")
41
 	}
41
 	}
42
 
42
 
43
-	return &RPCHandshakeResponse{
43
+	return &HandshakeResponse{
44
 		Type:      data[:4],
44
 		Type:      data[:4],
45
 		Flags:     data[4:8],
45
 		Flags:     data[4:8],
46
 		SenderPID: data[8:20],
46
 		SenderPID: data[8:20],

mtproto/rpc/rpc_nonce_request.go → mtproto/rpc/nonce_request.go Просмотреть файл

9
 	"github.com/juju/errors"
9
 	"github.com/juju/errors"
10
 )
10
 )
11
 
11
 
12
-type RPCNonceRequest struct {
12
+type NonceRequest struct {
13
 	KeySelector []byte
13
 	KeySelector []byte
14
 	CryptoTS    []byte
14
 	CryptoTS    []byte
15
 	Nonce       []byte
15
 	Nonce       []byte
16
 }
16
 }
17
 
17
 
18
-func (r *RPCNonceRequest) Bytes() []byte {
18
+func (r *NonceRequest) Bytes() []byte {
19
 	buf := &bytes.Buffer{}
19
 	buf := &bytes.Buffer{}
20
 
20
 
21
-	buf.Write(RPCTagNonce)
21
+	buf.Write(TagNonce)
22
 	buf.Write(r.KeySelector)
22
 	buf.Write(r.KeySelector)
23
-	buf.Write(RPCNonceCryptoAES)
23
+	buf.Write(NonceCryptoAES)
24
 	buf.Write(r.CryptoTS)
24
 	buf.Write(r.CryptoTS)
25
 	buf.Write(r.Nonce)
25
 	buf.Write(r.Nonce)
26
 
26
 
27
 	return buf.Bytes()
27
 	return buf.Bytes()
28
 }
28
 }
29
 
29
 
30
-func NewRPCNonceRequest(proxySecret []byte) (*RPCNonceRequest, error) {
30
+func NewNonceRequest(proxySecret []byte) (*NonceRequest, error) {
31
 	nonce := make([]byte, 16)
31
 	nonce := make([]byte, 16)
32
 	keySelector := make([]byte, 4)
32
 	keySelector := make([]byte, 4)
33
 	cryptoTS := make([]byte, 4)
33
 	cryptoTS := make([]byte, 4)
40
 	timestamp := time.Now().Truncate(time.Second).Unix() % 4294967296 // 256 ^ 4 - do not know how to name
40
 	timestamp := time.Now().Truncate(time.Second).Unix() % 4294967296 // 256 ^ 4 - do not know how to name
41
 	binary.LittleEndian.PutUint32(cryptoTS, uint32(timestamp))
41
 	binary.LittleEndian.PutUint32(cryptoTS, uint32(timestamp))
42
 
42
 
43
-	return &RPCNonceRequest{
43
+	return &NonceRequest{
44
 		KeySelector: keySelector,
44
 		KeySelector: keySelector,
45
 		CryptoTS:    cryptoTS,
45
 		CryptoTS:    cryptoTS,
46
 		Nonce:       nonce,
46
 		Nonce:       nonce,

mtproto/rpc/rpc_nonce_response.go → mtproto/rpc/nonce_response.go Просмотреть файл

6
 	"github.com/juju/errors"
6
 	"github.com/juju/errors"
7
 )
7
 )
8
 
8
 
9
-type RPCNonceResponse struct {
10
-	RPCNonceRequest
9
+type NonceResponse struct {
10
+	NonceRequest
11
 
11
 
12
-	RPCType []byte
13
-	Crypto  []byte
12
+	Type   []byte
13
+	Crypto []byte
14
 }
14
 }
15
 
15
 
16
-func (r *RPCNonceResponse) Bytes() []byte {
16
+func (r *NonceResponse) Bytes() []byte {
17
 	buf := &bytes.Buffer{}
17
 	buf := &bytes.Buffer{}
18
 
18
 
19
-	buf.Write(r.RPCType)
19
+	buf.Write(r.Type)
20
 	buf.Write(r.KeySelector)
20
 	buf.Write(r.KeySelector)
21
 	buf.Write(r.Crypto)
21
 	buf.Write(r.Crypto)
22
 	buf.Write(r.CryptoTS)
22
 	buf.Write(r.CryptoTS)
25
 	return buf.Bytes()
25
 	return buf.Bytes()
26
 }
26
 }
27
 
27
 
28
-func (r *RPCNonceResponse) Valid(req *RPCNonceRequest) error {
29
-	if !bytes.Equal(r.RPCType, RPCTagNonce) {
28
+func (r *NonceResponse) Valid(req *NonceRequest) error {
29
+	if !bytes.Equal(r.Type, TagNonce) {
30
 		return errors.New("Unexpected RPC type")
30
 		return errors.New("Unexpected RPC type")
31
 	}
31
 	}
32
-	if !bytes.Equal(r.Crypto, RPCNonceCryptoAES) {
32
+	if !bytes.Equal(r.Crypto, NonceCryptoAES) {
33
 		return errors.New("Unexpected crypto type")
33
 		return errors.New("Unexpected crypto type")
34
 	}
34
 	}
35
 	if !bytes.Equal(r.KeySelector, req.KeySelector) {
35
 	if !bytes.Equal(r.KeySelector, req.KeySelector) {
39
 	return nil
39
 	return nil
40
 }
40
 }
41
 
41
 
42
-func NewRPCNonceResponse(data []byte) (*RPCNonceResponse, error) {
42
+func NewNonceResponse(data []byte) (*NonceResponse, error) {
43
 	if len(data) != 32 {
43
 	if len(data) != 32 {
44
 		return nil, errors.New("Unexpected message length")
44
 		return nil, errors.New("Unexpected message length")
45
 	}
45
 	}
46
 
46
 
47
-	return &RPCNonceResponse{
48
-		RPCNonceRequest: RPCNonceRequest{
47
+	return &NonceResponse{
48
+		NonceRequest: NonceRequest{
49
 			KeySelector: data[4:8],
49
 			KeySelector: data[4:8],
50
 			CryptoTS:    data[12:16],
50
 			CryptoTS:    data[12:16],
51
 			Nonce:       data[16:],
51
 			Nonce:       data[16:],
52
 		},
52
 		},
53
-		RPCType: data[:4],
54
-		Crypto:  data[8:12],
53
+		Type:   data[:4],
54
+		Crypto: data[8:12],
55
 	}, nil
55
 	}, nil
56
 }
56
 }

+ 24
- 0
mtproto/rpc/proxy_flags.go Просмотреть файл

1
+package rpc
2
+
3
+import "encoding/binary"
4
+
5
+type proxyRequestFlags uint32
6
+
7
+const (
8
+	proxyRequestFlagsHasAdTag     proxyRequestFlags = 0x8
9
+	proxyRequestFlagsEncrypted                      = 0x2
10
+	proxyRequestFlagsMagic                          = 0x1000
11
+	proxyRequestFlagsExtMode2                       = 0x20000
12
+	proxyRequestFlagsIntermediate                   = 0x20000000
13
+	proxyRequestFlagsAbdridged                      = 0x40000000
14
+	proxyRequestFlagsQuickAck                       = 0x80000000
15
+)
16
+
17
+var proxyRequestFlagsEncryptedPrefix [8]byte
18
+
19
+func (r proxyRequestFlags) Bytes() []byte {
20
+	converted := make([]byte, 4)
21
+	binary.LittleEndian.PutUint32(converted, uint32(r))
22
+
23
+	return converted
24
+}

mtproto/rpc/rpc_proxy_request.go → mtproto/rpc/proxy_request.go Просмотреть файл

11
 	"github.com/9seconds/mtg/mtproto"
11
 	"github.com/9seconds/mtg/mtproto"
12
 )
12
 )
13
 
13
 
14
-type RPCProxyRequest struct {
15
-	Flags        RPCProxyRequestFlags
14
+type ProxyRequest struct {
15
+	Flags        proxyRequestFlags
16
 	ConnectionID []byte
16
 	ConnectionID []byte
17
 	OurIPPort    []byte
17
 	OurIPPort    []byte
18
 	ClientIPPort []byte
18
 	ClientIPPort []byte
20
 	Options      *mtproto.ConnectionOpts
20
 	Options      *mtproto.ConnectionOpts
21
 }
21
 }
22
 
22
 
23
-func (r *RPCProxyRequest) Bytes(message []byte) []byte {
23
+func (r *ProxyRequest) Bytes(message []byte) []byte {
24
 	buf := &bytes.Buffer{}
24
 	buf := &bytes.Buffer{}
25
 
25
 
26
 	flags := r.Flags
26
 	flags := r.Flags
27
 	if r.Options.QuickAck {
27
 	if r.Options.QuickAck {
28
-		flags |= RPCProxyRequestFlagsQuickAck
28
+		flags |= proxyRequestFlagsQuickAck
29
 	}
29
 	}
30
 
30
 
31
-	if bytes.HasPrefix(message, rpcProxyRequestFlagsEncryptedPrefix[:]) {
32
-		flags |= RPCProxyRequestFlagsEncrypted
31
+	if bytes.HasPrefix(message, proxyRequestFlagsEncryptedPrefix[:]) {
32
+		flags |= proxyRequestFlagsEncrypted
33
 	}
33
 	}
34
 
34
 
35
-	buf.Write(RPCTagProxyRequest)
35
+	buf.Write(TagProxyRequest)
36
 	buf.Write(flags.Bytes())
36
 	buf.Write(flags.Bytes())
37
 	buf.Write(r.ConnectionID[:])
37
 	buf.Write(r.ConnectionID[:])
38
 	buf.Write(r.ClientIPPort[:])
38
 	buf.Write(r.ClientIPPort[:])
39
 	buf.Write(r.OurIPPort[:])
39
 	buf.Write(r.OurIPPort[:])
40
-	buf.Write(RPCProxyRequestExtraSize)
41
-	buf.Write(RPCProxyRequestProxyTag)
40
+	buf.Write(ProxyRequestExtraSize)
41
+	buf.Write(ProxyRequestProxyTag)
42
 	buf.WriteByte(byte(len(r.ADTag)))
42
 	buf.WriteByte(byte(len(r.ADTag)))
43
 	buf.Write(r.ADTag)
43
 	buf.Write(r.ADTag)
44
 	buf.Write(bytes.Repeat([]byte{0x00}, buf.Len()%4))
44
 	buf.Write(bytes.Repeat([]byte{0x00}, buf.Len()%4))
47
 	return buf.Bytes()
47
 	return buf.Bytes()
48
 }
48
 }
49
 
49
 
50
-func NewRPCProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*RPCProxyRequest, error) {
51
-	flags := RPCProxyRequestFlagsHasAdTag | RPCProxyRequestFlagsMagic | RPCProxyRequestFlagsExtMode2
50
+func NewProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*ProxyRequest, error) {
51
+	flags := proxyRequestFlagsHasAdTag | proxyRequestFlagsMagic | proxyRequestFlagsExtMode2
52
 
52
 
53
 	switch opts.ConnectionType {
53
 	switch opts.ConnectionType {
54
 	case mtproto.ConnectionTypeAbridged:
54
 	case mtproto.ConnectionTypeAbridged:
55
-		flags |= RPCProxyRequestFlagsAbdridged
55
+		flags |= proxyRequestFlagsAbdridged
56
 	case mtproto.ConnectionTypeIntermediate:
56
 	case mtproto.ConnectionTypeIntermediate:
57
-		flags |= RPCProxyRequestFlagsIntermediate
57
+		flags |= proxyRequestFlagsIntermediate
58
 	}
58
 	}
59
 
59
 
60
-	request := RPCProxyRequest{
60
+	request := &ProxyRequest{
61
 		Flags:        flags,
61
 		Flags:        flags,
62
 		ADTag:        adTag,
62
 		ADTag:        adTag,
63
 		Options:      opts,
63
 		Options:      opts,
79
 	binary.LittleEndian.PutUint32(port[:], uint32(ownAddr.Port))
79
 	binary.LittleEndian.PutUint32(port[:], uint32(ownAddr.Port))
80
 	copy(request.OurIPPort[16:], port[:])
80
 	copy(request.OurIPPort[16:], port[:])
81
 
81
 
82
-	return &request, nil
82
+	return request, nil
83
 }
83
 }

+ 16
- 16
mtproto/rpc/rpc.go Просмотреть файл

1
 package rpc
1
 package rpc
2
 
2
 
3
 const (
3
 const (
4
-	RPCNonceSeqNo     = -2
5
-	RPCHandshakeSeqNo = -1
4
+	SeqNoNonce     = -2
5
+	SeqNoHandshake = -1
6
 )
6
 )
7
 
7
 
8
 var (
8
 var (
9
-	RPCTagCloseExt     = []byte{0xa2, 0x34, 0xb6, 0x5e}
10
-	RPCTagProxyAns     = []byte{0x0d, 0xda, 0x03, 0x44}
11
-	RPCTagSimpleAck    = []byte{0x9b, 0x40, 0xac, 0x3b}
12
-	RPCTagHandshake    = []byte{0xf5, 0xee, 0x82, 0x76}
13
-	RPCTagNonce        = []byte{0xaa, 0x87, 0xcb, 0x7a}
14
-	RPCTagProxyRequest = []byte{0xee, 0xf1, 0xce, 0x36}
9
+	TagCloseExt     = []byte{0xa2, 0x34, 0xb6, 0x5e}
10
+	TagProxyAns     = []byte{0x0d, 0xda, 0x03, 0x44}
11
+	TagSimpleAck    = []byte{0x9b, 0x40, 0xac, 0x3b}
12
+	TagHandshake    = []byte{0xf5, 0xee, 0x82, 0x76}
13
+	TagNonce        = []byte{0xaa, 0x87, 0xcb, 0x7a}
14
+	TagProxyRequest = []byte{0xee, 0xf1, 0xce, 0x36}
15
 
15
 
16
-	RPCNonceCryptoAES = []byte{0x01, 0x00, 0x00, 0x00}
16
+	NonceCryptoAES = []byte{0x01, 0x00, 0x00, 0x00}
17
 
17
 
18
-	RPCHandshakeFlags = []byte{0x00, 0x00, 0x00, 0x00}
18
+	HandshakeFlags = []byte{0x00, 0x00, 0x00, 0x00}
19
 
19
 
20
-	RPCProxyRequestExtraSize = []byte{0x18, 0x00, 0x00, 0x00}
21
-	RPCProxyRequestProxyTag  = []byte{0xae, 0x26, 0x1e, 0xdb}
20
+	ProxyRequestExtraSize = []byte{0x18, 0x00, 0x00, 0x00}
21
+	ProxyRequestProxyTag  = []byte{0xae, 0x26, 0x1e, 0xdb}
22
 
22
 
23
-	RPCHandshakeSenderPID = []byte{}
24
-	RPCHandshakePeerPID   = []byte{}
23
+	HandshakeSenderPID []byte
24
+	HandshakePeerPID   []byte
25
 )
25
 )
26
 
26
 
27
 func init() {
27
 func init() {
28
-	RPCHandshakeSenderPID = []byte("IPIPPRPDTIME")
29
-	RPCHandshakePeerPID = []byte("IPIPPRPDTIME")
28
+	HandshakeSenderPID = []byte("IPIPPRPDTIME")
29
+	HandshakePeerPID = []byte("IPIPPRPDTIME")
30
 }
30
 }

+ 0
- 21
mtproto/rpc/rpc_handshake_request.go Просмотреть файл

1
-package rpc
2
-
3
-import "bytes"
4
-
5
-type RPCHandshakeRequest struct {
6
-}
7
-
8
-func (r *RPCHandshakeRequest) Bytes() []byte {
9
-	buf := &bytes.Buffer{}
10
-
11
-	buf.Write(RPCTagHandshake)
12
-	buf.Write(RPCHandshakeFlags)
13
-	buf.Write(RPCHandshakeSenderPID)
14
-	buf.Write(RPCHandshakePeerPID)
15
-
16
-	return buf.Bytes()
17
-}
18
-
19
-func NewRPCHandshakeRequest() *RPCHandshakeRequest {
20
-	return &RPCHandshakeRequest{}
21
-}

+ 0
- 24
mtproto/rpc/rpc_proxy_flags.go Просмотреть файл

1
-package rpc
2
-
3
-import "encoding/binary"
4
-
5
-type RPCProxyRequestFlags uint32
6
-
7
-const (
8
-	RPCProxyRequestFlagsHasAdTag     RPCProxyRequestFlags = 0x8
9
-	RPCProxyRequestFlagsEncrypted                         = 0x2
10
-	RPCProxyRequestFlagsMagic                             = 0x1000
11
-	RPCProxyRequestFlagsExtMode2                          = 0x20000
12
-	RPCProxyRequestFlagsIntermediate                      = 0x20000000
13
-	RPCProxyRequestFlagsAbdridged                         = 0x40000000
14
-	RPCProxyRequestFlagsQuickAck                          = 0x80000000
15
-)
16
-
17
-var rpcProxyRequestFlagsEncryptedPrefix [8]byte
18
-
19
-func (r RPCProxyRequestFlags) Bytes() []byte {
20
-	converted := make([]byte, 4)
21
-	binary.LittleEndian.PutUint32(converted, uint32(r))
22
-
23
-	return converted
24
-}

+ 2
- 3
mtproto/wrappers/crypt.go Просмотреть файл

22
 
22
 
23
 var emptyIP = [4]byte{0x00, 0x00, 0x00, 0x00}
23
 var emptyIP = [4]byte{0x00, 0x00, 0x00, 0x00}
24
 
24
 
25
-func NewMiddleProxyCipherRWC(conn wrappers.ReadWriteCloserWithAddr, req *rpc.RPCNonceRequest, resp *rpc.RPCNonceResponse, secret []byte) wrappers.ReadWriteCloserWithAddr {
25
+func NewMiddleProxyCipherRWC(conn wrappers.ReadWriteCloserWithAddr, req *rpc.NonceRequest, resp *rpc.NonceResponse, secret []byte) wrappers.ReadWriteCloserWithAddr {
26
 	localAddr := conn.LocalAddr()
26
 	localAddr := conn.LocalAddr()
27
 	remoteAddr := conn.RemoteAddr()
27
 	remoteAddr := conn.RemoteAddr()
28
 
28
 
35
 	return wrappers.NewBlockCipherRWC(conn, enc, dec)
35
 	return wrappers.NewBlockCipherRWC(conn, enc, dec)
36
 }
36
 }
37
 
37
 
38
-func makeKeys(purpose CipherPurpose, req *rpc.RPCNonceRequest, resp *rpc.RPCNonceResponse,
39
-	client *net.TCPAddr, remote *net.TCPAddr, secret []byte) ([]byte, []byte) {
38
+func makeKeys(purpose CipherPurpose, req *rpc.NonceRequest, resp *rpc.NonceResponse, client *net.TCPAddr, remote *net.TCPAddr, secret []byte) ([]byte, []byte) {
40
 	message := bytes.Buffer{}
39
 	message := bytes.Buffer{}
41
 	message.Write(resp.Nonce[:])
40
 	message.Write(resp.Nonce[:])
42
 	message.Write(req.Nonce[:])
41
 	message.Write(req.Nonce[:])

+ 2
- 2
mtproto/wrappers/crypt_test.go Просмотреть файл

21
 	183, 6, 27, 38, 93, 178, 18}
21
 	183, 6, 27, 38, 93, 178, 18}
22
 
22
 
23
 func TestMakeKeys(t *testing.T) {
23
 func TestMakeKeys(t *testing.T) {
24
-	req, err := rpc.NewRPCNonceRequest(proxySecret)
24
+	req, err := rpc.NewNonceRequest(proxySecret)
25
 	assert.Nil(t, err)
25
 	assert.Nil(t, err)
26
 
26
 
27
 	copy(req.Nonce[:], []byte{24, 49, 53, 111, 198, 10, 235, 180, 230, 112, 92, 78, 1, 201, 106, 105})
27
 	copy(req.Nonce[:], []byte{24, 49, 53, 111, 198, 10, 235, 180, 230, 112, 92, 78, 1, 201, 106, 105})
28
 	binary.LittleEndian.PutUint32(req.CryptoTS[:], 1528396015)
28
 	binary.LittleEndian.PutUint32(req.CryptoTS[:], 1528396015)
29
 
29
 
30
-	resp := &rpc.RPCNonceResponse{}
30
+	resp := &rpc.NonceResponse{}
31
 	copy(resp.Nonce[:], []byte{247, 40, 210, 56, 65, 12, 101, 170, 216, 155, 14, 253, 250, 238, 219, 226})
31
 	copy(resp.Nonce[:], []byte{247, 40, 210, 56, 65, 12, 101, 170, 216, 155, 14, 253, 250, 238, 219, 226})
32
 
32
 
33
 	cltAddr := &net.TCPAddr{
33
 	cltAddr := &net.TCPAddr{

+ 5
- 5
mtproto/wrappers/proxy_request.go Просмотреть файл

17
 	wrappers.BufferedReader
17
 	wrappers.BufferedReader
18
 
18
 
19
 	conn wrappers.ReadWriteCloserWithAddr
19
 	conn wrappers.ReadWriteCloserWithAddr
20
-	req  *rpc.RPCProxyRequest
20
+	req  *rpc.ProxyRequest
21
 }
21
 }
22
 
22
 
23
 func (p *ProxyRequestReadWriteCloserWithAddr) Read(buf []byte) (int, error) {
23
 func (p *ProxyRequestReadWriteCloserWithAddr) Read(buf []byte) (int, error) {
29
 			return errors.Annotate(err, "Cannot read RPC tag")
29
 			return errors.Annotate(err, "Cannot read RPC tag")
30
 		}
30
 		}
31
 
31
 
32
-		if bytes.Equal(ansBuf.Bytes(), rpc.RPCTagCloseExt) {
32
+		if bytes.Equal(ansBuf.Bytes(), rpc.TagCloseExt) {
33
 			return p.readCloseExt()
33
 			return p.readCloseExt()
34
-		} else if bytes.Equal(ansBuf.Bytes(), rpc.RPCTagProxyAns) {
34
+		} else if bytes.Equal(ansBuf.Bytes(), rpc.TagProxyAns) {
35
 			return p.readProxyAns(buf)
35
 			return p.readProxyAns(buf)
36
-		} else if bytes.Equal(ansBuf.Bytes(), rpc.RPCTagSimpleAck) {
36
+		} else if bytes.Equal(ansBuf.Bytes(), rpc.TagSimpleAck) {
37
 			return p.readSimpleAck()
37
 			return p.readSimpleAck()
38
 		}
38
 		}
39
 
39
 
99
 }
99
 }
100
 
100
 
101
 func NewProxyRequestRWC(conn wrappers.ReadWriteCloserWithAddr, connOpts *mtproto.ConnectionOpts, adTag []byte) (wrappers.ReadWriteCloserWithAddr, error) {
101
 func NewProxyRequestRWC(conn wrappers.ReadWriteCloserWithAddr, connOpts *mtproto.ConnectionOpts, adTag []byte) (wrappers.ReadWriteCloserWithAddr, error) {
102
-	req, err := rpc.NewRPCProxyRequest(connOpts.ClientAddr, conn.LocalAddr(), connOpts, adTag)
102
+	req, err := rpc.NewProxyRequest(connOpts.ClientAddr, conn.LocalAddr(), connOpts, adTag)
103
 	if err != nil {
103
 	if err != nil {
104
 		return nil, errors.Annotate(err, "Cannot create new RPC proxy request")
104
 		return nil, errors.Annotate(err, "Cannot create new RPC proxy request")
105
 	}
105
 	}

+ 12
- 10
telegram/middle.go Просмотреть файл

50
 }
50
 }
51
 
51
 
52
 func (t *middleTelegram) Init(connOpts *mtproto.ConnectionOpts, conn wrappers.ReadWriteCloserWithAddr) (wrappers.ReadWriteCloserWithAddr, error) {
52
 func (t *middleTelegram) Init(connOpts *mtproto.ConnectionOpts, conn wrappers.ReadWriteCloserWithAddr) (wrappers.ReadWriteCloserWithAddr, error) {
53
-	rpcNonceConn := mtwrappers.NewFrameRWC(conn, rpc.RPCNonceSeqNo)
53
+	rpcNonceConn := mtwrappers.NewFrameRWC(conn, rpc.SeqNoNonce)
54
 
54
 
55
 	rpcNonceReq, err := t.sendRPCNonceRequest(rpcNonceConn)
55
 	rpcNonceReq, err := t.sendRPCNonceRequest(rpcNonceConn)
56
 	if err != nil {
56
 	if err != nil {
62
 	}
62
 	}
63
 
63
 
64
 	secureConn := mtwrappers.NewMiddleProxyCipherRWC(conn, rpcNonceReq, rpcNonceResp, t.proxySecret)
64
 	secureConn := mtwrappers.NewMiddleProxyCipherRWC(conn, rpcNonceReq, rpcNonceResp, t.proxySecret)
65
-	secureConn = mtwrappers.NewFrameRWC(secureConn, rpc.RPCHandshakeSeqNo)
65
+	secureConn = mtwrappers.NewFrameRWC(secureConn, rpc.SeqNoHandshake)
66
 
66
 
67
 	rpcHandshakeReq, err := t.sendRPCHandshakeRequest(secureConn)
67
 	rpcHandshakeReq, err := t.sendRPCHandshakeRequest(secureConn)
68
 	if err != nil {
68
 	if err != nil {
76
 	return mtwrappers.NewProxyRequestRWC(secureConn, connOpts, t.conf.AdTag)
76
 	return mtwrappers.NewProxyRequestRWC(secureConn, connOpts, t.conf.AdTag)
77
 }
77
 }
78
 
78
 
79
-func (t *middleTelegram) sendRPCNonceRequest(conn io.Writer) (*rpc.RPCNonceRequest, error) {
80
-	rpcNonceReq, err := rpc.NewRPCNonceRequest(t.proxySecret)
79
+func (t *middleTelegram) sendRPCNonceRequest(conn io.Writer) (*rpc.NonceRequest, error) {
80
+	rpcNonceReq, err := rpc.NewNonceRequest(t.proxySecret)
81
 	if err != nil {
81
 	if err != nil {
82
 		return nil, errors.Annotate(err, "Cannot create RPC nonce request")
82
 		return nil, errors.Annotate(err, "Cannot create RPC nonce request")
83
 	}
83
 	}
88
 	return rpcNonceReq, nil
88
 	return rpcNonceReq, nil
89
 }
89
 }
90
 
90
 
91
-func (t *middleTelegram) receiveRPCNonceResponse(conn io.Reader, req *rpc.RPCNonceRequest) (*rpc.RPCNonceResponse, error) {
91
+func (t *middleTelegram) receiveRPCNonceResponse(conn io.Reader, req *rpc.NonceRequest) (*rpc.NonceResponse, error) {
92
 	var ans [128]byte
92
 	var ans [128]byte
93
 
93
 
94
 	n, err := conn.Read(ans[:])
94
 	n, err := conn.Read(ans[:])
95
 	if err != nil {
95
 	if err != nil {
96
 		return nil, errors.Annotate(err, "Cannot read RPC nonce response")
96
 		return nil, errors.Annotate(err, "Cannot read RPC nonce response")
97
 	}
97
 	}
98
-	rpcNonceResp, err := rpc.NewRPCNonceResponse(ans[:n])
98
+
99
+	rpcNonceResp, err := rpc.NewNonceResponse(ans[:n])
99
 	if err != nil {
100
 	if err != nil {
100
 		return nil, errors.Annotate(err, "Cannot initialize RPC nonce response")
101
 		return nil, errors.Annotate(err, "Cannot initialize RPC nonce response")
101
 	}
102
 	}
106
 	return rpcNonceResp, nil
107
 	return rpcNonceResp, nil
107
 }
108
 }
108
 
109
 
109
-func (t *middleTelegram) sendRPCHandshakeRequest(conn io.Writer) (*rpc.RPCHandshakeRequest, error) {
110
-	req := rpc.NewRPCHandshakeRequest()
110
+func (t *middleTelegram) sendRPCHandshakeRequest(conn io.Writer) (*rpc.HandshakeRequest, error) {
111
+	req := rpc.NewHandshakeRequest()
111
 	if _, err := conn.Write(req.Bytes()); err != nil {
112
 	if _, err := conn.Write(req.Bytes()); err != nil {
112
 		return nil, errors.Annotate(err, "Cannot send RPC handshake request")
113
 		return nil, errors.Annotate(err, "Cannot send RPC handshake request")
113
 	}
114
 	}
115
 	return req, nil
116
 	return req, nil
116
 }
117
 }
117
 
118
 
118
-func (t *middleTelegram) receiveRPCHandshakeResponse(conn io.Reader, req *rpc.RPCHandshakeRequest) (*rpc.RPCHandshakeResponse, error) {
119
+func (t *middleTelegram) receiveRPCHandshakeResponse(conn io.Reader, req *rpc.HandshakeRequest) (*rpc.HandshakeResponse, error) {
119
 	var ans [128]byte
120
 	var ans [128]byte
120
 
121
 
121
 	n, err := conn.Read(ans[:])
122
 	n, err := conn.Read(ans[:])
122
 	if err != nil {
123
 	if err != nil {
123
 		return nil, errors.Annotate(err, "Cannot read RPC handshake response")
124
 		return nil, errors.Annotate(err, "Cannot read RPC handshake response")
124
 	}
125
 	}
125
-	rpcHandshakeResp, err := rpc.NewRPCHandshakeResponse(ans[:n])
126
+
127
+	rpcHandshakeResp, err := rpc.NewHandshakeResponse(ans[:n])
126
 	if err != nil {
128
 	if err != nil {
127
 		return nil, errors.Annotate(err, "Cannot initialize RPC handshake response")
129
 		return nil, errors.Annotate(err, "Cannot initialize RPC handshake response")
128
 	}
130
 	}

Загрузка…
Отмена
Сохранить