linting the code

This commit is contained in:
9seconds
2019-10-11 09:41:18 +03:00
parent 432e2970a0
commit 5009859a1e
50 changed files with 172 additions and 55 deletions
+5 -2
View File
@@ -58,6 +58,7 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
decryptor.XORKeyStream(decryptedFrame.Bytes(), fm.Bytes())
magic := decryptedFrame.Magic()
switch {
case bytes.Equal(magic, conntypes.ConnectionTagAbridged):
c.connectionType = conntypes.ConnectionTypeAbridged
@@ -66,7 +67,7 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
case bytes.Equal(magic, conntypes.ConnectionTagSecure):
c.connectionType = conntypes.ConnectionTypeSecure
default:
return nil, errors.New("Unknown connection type")
return nil, errors.New("unknown connection type")
}
c.connectionProtocol = conntypes.ConnectionProtocolIPv4
@@ -81,8 +82,9 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
antiReplayKey := decryptedFrame.Unique()
if antireplay.Cache.Has(antiReplayKey) {
return nil, errors.New("Replay attack is detected")
return nil, errors.New("replay attack is detected")
}
antireplay.Cache.Add(antiReplayKey)
return stream.NewObfuscated2(socket, encryptor, decryptor), nil
@@ -92,6 +94,7 @@ func (c *ClientProtocol) ReadFrame(socket conntypes.StreamReader) (fm Frame, err
if _, err = io.ReadFull(handshakeReader{socket}, fm.Bytes()); err != nil {
err = fmt.Errorf("cannot extract obfuscated2 frame: %w", err)
}
return
}
+2
View File
@@ -17,6 +17,7 @@ func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.StreamReadWriteC
if err != nil {
return nil, fmt.Errorf("cannot dial to telegram: %w", err)
}
conn = stream.NewTimeout(conn)
conn = stream.NewCtx(req.Ctx, req.Cancel, conn)
fm := generateFrame(req.ClientProtocol)
@@ -45,6 +46,7 @@ func generateFrame(cp protocol.ClientProtocol) (fm Frame) {
if _, err := rand.Read(data); err != nil {
continue
}
if data[0] == 0xef {
continue
}