Skip to content

Commit

Permalink
Merge pull request #265 from yunkon-kim/fix-invalid-argument
Browse files Browse the repository at this point in the history
Specify the size of buffer when writing a packet
  • Loading branch information
yunkon-kim authored Mar 29, 2022
2 parents a67d883 + c0b29d9 commit d4bef4f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 6 additions & 1 deletion poc-cb-net/cmd/admin-web/admin-web.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ func handleTestSpecification(etcdClient *clientv3.Client, responseText []byte) {

// Get a networking rule of a cloud adaptive network
keyNetworkingRule := fmt.Sprint(etcdkey.NetworkingRule + "/" + testSpecification.CLADNetID)
CBLogger.Debugf("Get - %v", keyNetworkingRule)
resp, err := etcdClient.Get(context.TODO(), keyNetworkingRule, clientv3.WithPrefix())
if err != nil {
CBLogger.Error(err)
}

CBLogger.Tracef("Get resp: %+v", resp)

for _, kv := range resp.Kvs {

var peer model.Peer
Expand Down Expand Up @@ -275,6 +278,7 @@ func handleControlCommand(etcdClient *clientv3.Client, responseText string) {

// Get a networking rule of a cloud adaptive network
keyNetworkingRule := fmt.Sprint(etcdkey.NetworkingRule + "/" + cladnetID)
CBLogger.Debugf("Get - %v", keyNetworkingRule)
resp, err := etcdClient.Get(context.TODO(), keyNetworkingRule, clientv3.WithPrefix())
if err != nil {
CBLogger.Error(err)
Expand All @@ -283,7 +287,7 @@ func handleControlCommand(etcdClient *clientv3.Client, responseText string) {
for _, kv := range resp.Kvs {
key := string(kv.Key)
CBLogger.Tracef("Key : %v", key)
CBLogger.Tracef("The peer: %v", kv.Value)
CBLogger.Tracef("The peer: %v", string(kv.Value))

var peer model.Peer
err := json.Unmarshal(kv.Value, &peer)
Expand All @@ -294,6 +298,7 @@ func handleControlCommand(etcdClient *clientv3.Client, responseText string) {
// Put the evaluation specification of the CLADNet to the etcd
keyControlCommand := fmt.Sprint(etcdkey.ControlCommand + "/" + peer.CLADNetID + "/" + peer.HostID)

CBLogger.Debugf("Put - %v", keyControlCommand)
cmdMessageBody := cmd.BuildCommandMessage(controlCommand, controlCommandOption)
CBLogger.Tracef("%#v", cmdMessageBody)
//spec := message.Text
Expand Down
7 changes: 4 additions & 3 deletions poc-cb-net/cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ func watchHostNetworkInformation(wg *sync.WaitGroup, etcdClient *clientv3.Client
peer.PublicIPv4Address = hostNetworkInformation.PublicIP
}

CBLogger.Debugf("Put \"%v\"", keyNetworkingRuleOfPeer)
doc, _ := json.Marshal(peer)
CBLogger.Debugf("Put - %v", keyNetworkingRuleOfPeer)
CBLogger.Tracef("Value: %#v", peer)

doc, _ := json.Marshal(peer)
if _, err := etcdClient.Put(context.TODO(), keyNetworkingRuleOfPeer, string(doc)); err != nil {
CBLogger.Error(err)
}
Expand All @@ -250,7 +251,7 @@ func watchHostNetworkInformation(wg *sync.WaitGroup, etcdClient *clientv3.Client
func tryToAcquireWorkload(etcdClient *clientv3.Client, controllerID string, key string, revision int64) bool {
CBLogger.Debugf("Start (%s) .........", controllerID)
// Key to lease temporally by which each cb-network controller can distinguish each updated value
keyToLease := fmt.Sprintf("lease/%s-%d", key, revision)
keyToLease := fmt.Sprintf("lease%s-%d", key, revision)
// fmt.Printf("%#v\n", keyPrefix)

// Self-assign a workload by Compare-and-Swap (CAS) and Lease
Expand Down
9 changes: 7 additions & 2 deletions poc-cb-net/pkg/cb-network/cb-network.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,11 @@ func (cbnetwork *CBNetwork) encapsulate(wg *sync.WaitGroup) error {
}

bufToWrite = ciphertext
plen = len(ciphertext)
}

// Send packet
nWriteToUDP, errWriteToUDP := cbnetwork.listenConnection.WriteToUDP(bufToWrite, remoteAddr)
nWriteToUDP, errWriteToUDP := cbnetwork.listenConnection.WriteToUDP(bufToWrite[:plen], remoteAddr)
if errWriteToUDP != nil || nWriteToUDP == 0 {
CBLogger.Errorf("Error(%d len): %s", nWriteToUDP, errWriteToUDP)
}
Expand All @@ -525,6 +526,9 @@ func (cbnetwork *CBNetwork) decapsulate(wg *sync.WaitGroup) error {
CBLogger.Tracef("[Decapsulation] Received %d bytes from %v", n, addr)

bufToWrite := buf[:n]
// if n < BUFFERSIZE-1 {
// buf[n+1] = '\n'
// }

if cbnetwork.isEncryptionEnabled {
// Decrypt ciphertext by private key
Expand All @@ -540,6 +544,7 @@ func (cbnetwork *CBNetwork) decapsulate(wg *sync.WaitGroup) error {
continue
}
bufToWrite = plaintext
n = len(plaintext)
}

// Parse header
Expand All @@ -551,7 +556,7 @@ func (cbnetwork *CBNetwork) decapsulate(wg *sync.WaitGroup) error {
// To be determined.

// Write to TUN interface
nWrite, errWrite := cbnetwork.Interface.Write(bufToWrite)
nWrite, errWrite := cbnetwork.Interface.Write(bufToWrite[:n])
if errWrite != nil || nWrite == 0 {
CBLogger.Errorf("Error(%d len): %s", nWrite, errWrite)
}
Expand Down

0 comments on commit d4bef4f

Please sign in to comment.