Done some TODOs

legacy-v1
Qian Wang 6 years ago
parent 30c3936154
commit 73aefdeeeb

@ -7,10 +7,12 @@ version=$(shell ver=$$(git log -n 1 --pretty=oneline --format=%D | awk -F, '{pri
echo $$ver)
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:
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:
mv build/ck-* /usr/local/bin

@ -209,7 +209,6 @@ func main() {
}
wg.Wait()
// TODO: ipv6
listener, err := net.Listen("tcp", sta.SS_LOCAL_HOST+":"+sta.SS_LOCAL_PORT)
if err != nil {
log.Fatal(err)

@ -72,32 +72,20 @@ func (s *Stream) recvNewFrame() {
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 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
}
s.pushFrame(f)
continue
}
// For the ease of demonstration, assume seq is uint8, i.e. it wraps around after 255
fs := &frameNode{
f.Seq,
0,
f,
}
// TODO: if a malicious client resend a previously sent seq number, what will happen?
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)
// 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
@ -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
for len(s.sh) > 0 && s.sh[0].seq == s.nextRecvSeq {
frame := heap.Pop(&s.sh).(*frameNode).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
}
s.pushFrame(frame)
}
}
}
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
func (stream *Stream) passiveClose() error {
func (stream *Stream) passiveClose() {
stream.heliumMask.Do(func() { close(stream.die) })
stream.session.delStream(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
@ -148,8 +146,6 @@ func (stream *Stream) Close() error {
// This is called in session.Close() to avoid mutex deadlock
// We don't notify the remote because session.Close() is always
// called when the session is passively closed
func (stream *Stream) closeNoDelMap() error {
func (stream *Stream) closeNoDelMap() {
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)
if err != nil {
return n, err
// TODO
}
if sb.AddTxCredit(-int64(n)) < 0 {
log.Println(ErrNoTxCredit)

@ -4,6 +4,7 @@ import (
"crypto"
"encoding/base64"
"encoding/json"
"errors"
"io/ioutil"
"strings"
"sync"
@ -82,17 +83,6 @@ func ssvToJson(ssv string) (ret []byte) {
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
func (sta *State) ParseConfig(conf string) (err error) {
var content []byte
@ -108,22 +98,22 @@ func (sta *State) ParseConfig(conf string) (err error) {
var preParse rawConfig
err = json.Unmarshal(content, &preParse)
if err != nil {
return err
return errors.New("Failed to unmarshal: " + err.Error())
}
sta.WebServerAddr = preParse.WebServerAddr
pvBytes, err := base64.StdEncoding.DecodeString(preParse.PrivateKey)
if err != nil {
return err
return errors.New("Failed to decode private key: " + err.Error())
}
var pv [32]byte
copy(pv[:], pvBytes)
sta.staticPv = &pv
adminUID, err := parseAdminUID(preParse.AdminUID)
adminUID, err := base64.StdEncoding.DecodeString(preParse.AdminUID)
if err != nil {
return err
return errors.New("Failed to decode AdminUID: " + err.Error())
}
sta.AdminUID = adminUID
return nil

Loading…
Cancel
Save