mirror of https://github.com/cbeuw/Cloak
Done some TODOs
This commit is contained in:
parent
30c3936154
commit
73aefdeeeb
6
Makefile
6
Makefile
|
|
@ -7,10 +7,12 @@ version=$(shell ver=$$(git log -n 1 --pretty=oneline --format=%D | awk -F, '{pri
|
||||||
echo $$ver)
|
echo $$ver)
|
||||||
|
|
||||||
client:
|
client:
|
||||||
go build -ldflags "-X main.version=${version}" -o ./build/ck-client ./cmd/ck-client
|
go build -ldflags "-X main.version=${version}" ./cmd/ck-client
|
||||||
|
mv ck-client* ./build
|
||||||
|
|
||||||
server:
|
server:
|
||||||
go build -ldflags "-X main.version=${version}" -o ./build/ck-server ./cmd/ck-server
|
go build -ldflags "-X main.version=${version}" ./cmd/ck-server
|
||||||
|
mv ck-server* ./build
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mv build/ck-* /usr/local/bin
|
mv build/ck-* /usr/local/bin
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,6 @@ func main() {
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// TODO: ipv6
|
|
||||||
listener, err := net.Listen("tcp", sta.SS_LOCAL_HOST+":"+sta.SS_LOCAL_PORT)
|
listener, err := net.Listen("tcp", sta.SS_LOCAL_HOST+":"+sta.SS_LOCAL_PORT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
||||||
|
|
@ -72,32 +72,20 @@ func (s *Stream) recvNewFrame() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when there's no ooo packages in heap and we receive the next package in order
|
||||||
if len(s.sh) == 0 && f.Seq == s.nextRecvSeq {
|
if len(s.sh) == 0 && f.Seq == s.nextRecvSeq {
|
||||||
if f.Closing == 1 {
|
s.pushFrame(f)
|
||||||
s.sortedBufCh <- []byte{}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s.sortedBufCh <- f.Payload
|
|
||||||
|
|
||||||
s.nextRecvSeq += 1
|
|
||||||
if s.nextRecvSeq == 0 {
|
|
||||||
// when nextN is wrapped, wrapMode becomes false and rev+1
|
|
||||||
s.rev += 1
|
|
||||||
s.wrapMode = false
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// For the ease of demonstration, assume seq is uint8, i.e. it wraps around after 255
|
|
||||||
fs := &frameNode{
|
fs := &frameNode{
|
||||||
f.Seq,
|
f.Seq,
|
||||||
0,
|
0,
|
||||||
f,
|
f,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: if a malicious client resend a previously sent seq number, what will happen?
|
|
||||||
if fs.seq < s.nextRecvSeq {
|
if fs.seq < s.nextRecvSeq {
|
||||||
|
// For the ease of demonstration, assume seq is uint8, i.e. it wraps around after 255
|
||||||
// e.g. we are on rev=0 (wrap has not happened yet)
|
// e.g. we are on rev=0 (wrap has not happened yet)
|
||||||
// and we get the order of recv as 253 254 0 1
|
// and we get the order of recv as 253 254 0 1
|
||||||
// after 254, nextN should be 255, but 0 is received and 0 < 255
|
// after 254, nextN should be 255, but 0 is received and 0 < 255
|
||||||
|
|
@ -118,21 +106,24 @@ func (s *Stream) recvNewFrame() {
|
||||||
// Keep popping from the heap until empty or to the point that the wanted seq was not received
|
// Keep popping from the heap until empty or to the point that the wanted seq was not received
|
||||||
for len(s.sh) > 0 && s.sh[0].seq == s.nextRecvSeq {
|
for len(s.sh) > 0 && s.sh[0].seq == s.nextRecvSeq {
|
||||||
frame := heap.Pop(&s.sh).(*frameNode).frame
|
frame := heap.Pop(&s.sh).(*frameNode).frame
|
||||||
|
s.pushFrame(frame)
|
||||||
if frame.Closing == 1 {
|
|
||||||
s.sortedBufCh <- []byte{}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
payload := frame.Payload
|
|
||||||
s.sortedBufCh <- payload
|
|
||||||
|
|
||||||
s.nextRecvSeq += 1
|
|
||||||
if s.nextRecvSeq == 0 {
|
|
||||||
// when nextN is wrapped, wrapMode becomes false and rev+1
|
|
||||||
s.rev += 1
|
|
||||||
s.wrapMode = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Stream) pushFrame(f *Frame) {
|
||||||
|
if f.Closing == 1 {
|
||||||
|
s.sortedBufCh <- []byte{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s.sortedBufCh <- f.Payload
|
||||||
|
|
||||||
|
s.nextRecvSeq += 1
|
||||||
|
if s.nextRecvSeq == 0 {
|
||||||
|
// when nextN is wrapped, wrapMode becomes false and rev+1
|
||||||
|
s.rev += 1
|
||||||
|
s.wrapMode = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,12 +110,10 @@ func (stream *Stream) Write(in []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// only close locally. Used when the stream close is notified by the remote
|
// only close locally. Used when the stream close is notified by the remote
|
||||||
func (stream *Stream) passiveClose() error {
|
func (stream *Stream) passiveClose() {
|
||||||
stream.heliumMask.Do(func() { close(stream.die) })
|
stream.heliumMask.Do(func() { close(stream.die) })
|
||||||
stream.session.delStream(stream.id)
|
stream.session.delStream(stream.id)
|
||||||
log.Printf("%v passive closing\n", stream.id)
|
log.Printf("%v passive closing\n", stream.id)
|
||||||
// TODO: really need to return an error?
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// active close. Close locally and tell the remote that this stream is being closed
|
// active close. Close locally and tell the remote that this stream is being closed
|
||||||
|
|
@ -148,8 +146,6 @@ func (stream *Stream) Close() error {
|
||||||
// This is called in session.Close() to avoid mutex deadlock
|
// This is called in session.Close() to avoid mutex deadlock
|
||||||
// We don't notify the remote because session.Close() is always
|
// We don't notify the remote because session.Close() is always
|
||||||
// called when the session is passively closed
|
// called when the session is passively closed
|
||||||
func (stream *Stream) closeNoDelMap() error {
|
func (stream *Stream) closeNoDelMap() {
|
||||||
stream.heliumMask.Do(func() { close(stream.die) })
|
stream.heliumMask.Do(func() { close(stream.die) })
|
||||||
// TODO: really need to return an error?
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ func (sb *switchboard) send(data []byte) (int, error) {
|
||||||
n, err := ce.remoteConn.Write(data)
|
n, err := ce.remoteConn.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
if sb.AddTxCredit(-int64(n)) < 0 {
|
if sb.AddTxCredit(-int64(n)) < 0 {
|
||||||
log.Println(ErrNoTxCredit)
|
log.Println(ErrNoTxCredit)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -82,17 +83,6 @@ func ssvToJson(ssv string) (ret []byte) {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// base64 encoded 32 byte adminUID
|
|
||||||
func parseAdminUID(b64 string) ([]byte, error) {
|
|
||||||
uid, err := base64.StdEncoding.DecodeString(b64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return uid, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: specify which parse fails
|
|
||||||
|
|
||||||
// ParseConfig parses the config (either a path to json or in-line ssv config) into a State variable
|
// ParseConfig parses the config (either a path to json or in-line ssv config) into a State variable
|
||||||
func (sta *State) ParseConfig(conf string) (err error) {
|
func (sta *State) ParseConfig(conf string) (err error) {
|
||||||
var content []byte
|
var content []byte
|
||||||
|
|
@ -108,22 +98,22 @@ func (sta *State) ParseConfig(conf string) (err error) {
|
||||||
var preParse rawConfig
|
var preParse rawConfig
|
||||||
err = json.Unmarshal(content, &preParse)
|
err = json.Unmarshal(content, &preParse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.New("Failed to unmarshal: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
sta.WebServerAddr = preParse.WebServerAddr
|
sta.WebServerAddr = preParse.WebServerAddr
|
||||||
|
|
||||||
pvBytes, err := base64.StdEncoding.DecodeString(preParse.PrivateKey)
|
pvBytes, err := base64.StdEncoding.DecodeString(preParse.PrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.New("Failed to decode private key: " + err.Error())
|
||||||
}
|
}
|
||||||
var pv [32]byte
|
var pv [32]byte
|
||||||
copy(pv[:], pvBytes)
|
copy(pv[:], pvBytes)
|
||||||
sta.staticPv = &pv
|
sta.staticPv = &pv
|
||||||
|
|
||||||
adminUID, err := parseAdminUID(preParse.AdminUID)
|
adminUID, err := base64.StdEncoding.DecodeString(preParse.AdminUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.New("Failed to decode AdminUID: " + err.Error())
|
||||||
}
|
}
|
||||||
sta.AdminUID = adminUID
|
sta.AdminUID = adminUID
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue