Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
229 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flynet | ||
package fly | ||
|
||
import ( | ||
"crypto/aes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package fly | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
type Conn struct { | ||
net.Conn | ||
*Cipher | ||
} | ||
|
||
func NewConn(con net.Conn, cipher *Cipher) *Conn { | ||
return &Conn{ | ||
Conn: con, | ||
Cipher: cipher, | ||
} | ||
} | ||
|
||
// dial server and send request addr of client | ||
func DialWithAddr(server string, addr []byte) *Conn { | ||
conn, err := net.Dial("tcp", server) | ||
if err != nil { | ||
logger.Println("Dial server failed!", err) | ||
return nil | ||
} | ||
newConn := NewConn(conn, NewCipherInstance()) | ||
if _, err := newConn.Write(addr); err != nil { | ||
logger.Println("write addr to server failed!", err) | ||
return nil | ||
} | ||
return newConn | ||
} | ||
|
||
func (conn *Conn) Write(b []byte) (n int, err error) { | ||
buff := make([]byte, 1024) | ||
if len(buff) > len(b) { | ||
buff = buff[:len(b)] | ||
} else { | ||
buff = make([]byte, len(b)) | ||
} | ||
|
||
conn.Encrypt(buff, b) | ||
n, err = conn.Conn.Write(buff) | ||
return | ||
} | ||
|
||
func (conn *Conn) Read(b []byte) (n int, err error) { | ||
buff := make([]byte, 1024) | ||
n, err = conn.Conn.Read(buff) | ||
|
||
//fmt.Println("before", buff[:n]) | ||
if n > 0 { | ||
b = b[:n] | ||
conn.Decrypt(b, buff[:n]) | ||
//fmt.Println("after", b[:n]) | ||
} | ||
return | ||
} | ||
|
||
func (conn *Conn) Close() error { | ||
err := conn.Conn.Close() | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flynet | ||
package fly | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flynet | ||
package fly | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.