Skip to content

Commit 6e74e62

Browse files
committed
ran go fmt on netcat
1 parent 6f60735 commit 6e74e62

File tree

3 files changed

+149
-148
lines changed

3 files changed

+149
-148
lines changed

netcat/main.go

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,92 @@
11
package main
22

33
import (
4-
"fmt"
5-
golog "log"
6-
"os"
7-
"io"
8-
"sync"
9-
"strconv"
10-
"flag"
11-
12-
"github.com/netsec-ethz/scion-apps/netcat/utils"
13-
"github.com/scionproto/scion/go/lib/log"
4+
"flag"
5+
"fmt"
6+
"io"
7+
golog "log"
8+
"os"
9+
"strconv"
10+
"sync"
11+
12+
"github.com/netsec-ethz/scion-apps/netcat/utils"
13+
"github.com/scionproto/scion/go/lib/log"
1414
)
1515

1616
func printUsage() {
1717
fmt.Println("netcat [flags] host-address port")
1818
fmt.Println("The host address is specified as ISD-AS,[IP Address]")
1919
fmt.Println("Example SCION address: 17-ffaa:1:bfd,[127.0.0.1]:42002")
2020
fmt.Println("Available flags:")
21+
fmt.Println(" -h: Show help")
2122
fmt.Println(" -P: Use IA when resolving SCIOND socket path")
2223
fmt.Println(" -b: Send an extra byte before sending the actual data")
2324
}
2425

2526
func main() {
26-
log.SetupLogConsole("debug")
27-
log.Debug("Launching netcat")
28-
29-
var (
30-
SERVER_ADDRESS string
31-
PORT uint16
32-
USE_IA_SCIOND_PATH bool
33-
SEND_PIPER_BYTE bool
34-
)
35-
36-
flag.BoolVar(&USE_IA_SCIOND_PATH, "P", false, "Use IA SCIOND Path")
37-
flag.BoolVar(&SEND_PIPER_BYTE, "b", false, "Send extra byte")
38-
flag.Parse()
39-
tail := flag.Args()
40-
if len(tail) != 2 {
41-
golog.Panicf("Number of arguments is not two! Arguments: %v", tail)
42-
}
43-
44-
SERVER_ADDRESS = tail[0]
45-
port64, err := strconv.ParseUint(tail[1], 10, 16)
46-
if err != nil {
47-
golog.Panicf("Can't parse port string %s: %v", port64, err)
48-
}
49-
PORT = uint16(port64)
50-
51-
52-
// Initialize SCION library
53-
err = utils.InitSCION("", "", USE_IA_SCIOND_PATH)
54-
if err != nil {
55-
golog.Panicf("Error initializing SCION connection: %v", err)
56-
}
57-
58-
conn, err := utils.DialSCION(fmt.Sprintf("%s:%v", SERVER_ADDRESS, PORT))
59-
if err != nil {
60-
golog.Panicf("Error dialing remote: %v", err)
61-
}
62-
63-
log.Debug("Connected!")
64-
65-
if SEND_PIPER_BYTE {
66-
_, err := conn.Write([]byte {71})
67-
if err != nil {
68-
golog.Panicf("Error writing extra byte: %v", err)
69-
}
70-
71-
log.Debug("Sent extra byte!")
72-
}
73-
74-
close := func() {
75-
conn.Close()
76-
}
77-
78-
var once sync.Once
79-
go func() {
80-
io.Copy(os.Stdout, conn)
81-
once.Do(close)
82-
}()
83-
io.Copy(conn, os.Stdin)
84-
once.Do(close)
85-
86-
log.Debug("Exiting snetcat...")
27+
log.SetupLogConsole("debug")
28+
log.Debug("Launching netcat")
29+
30+
var (
31+
serverAddress string
32+
port uint16
33+
useIASCIONDPath bool
34+
extraByte bool
35+
)
36+
flag.BoolVar(&showHelp, "h", false, "Show help")
37+
flag.BoolVar(&USE_IA_SCIOND_PATH, "P", false, "Use IA SCIOND Path")
38+
flag.BoolVar(&SEND_PIPER_BYTE, "b", false, "Send extra byte")
39+
flag.Parse()
40+
if showHelp {
41+
printUsage()
42+
return
43+
}
44+
45+
tail := flag.Args()
46+
if len(tail) != 2 {
47+
golog.Panicf("Number of arguments is not two! Arguments: %v", tail)
48+
}
49+
50+
SERVER_ADDRESS = tail[0]
51+
port64, err := strconv.ParseUint(tail[1], 10, 16)
52+
if err != nil {
53+
golog.Panicf("Can't parse port string %v: %v", port64, err)
54+
}
55+
PORT = uint16(port64)
56+
57+
// Initialize SCION library
58+
err = utils.InitSCION("", "", USE_IA_SCIOND_PATH)
59+
if err != nil {
60+
golog.Panicf("Error initializing SCION connection: %v", err)
61+
}
62+
63+
conn, err := utils.DialSCION(fmt.Sprintf("%s:%v", SERVER_ADDRESS, PORT))
64+
if err != nil {
65+
golog.Panicf("Error dialing remote: %v", err)
66+
}
67+
68+
log.Debug("Connected!")
69+
70+
if SEND_PIPER_BYTE {
71+
_, err := conn.Write([]byte{71})
72+
if err != nil {
73+
golog.Panicf("Error writing extra byte: %v", err)
74+
}
75+
76+
log.Debug("Sent extra byte!")
77+
}
78+
79+
close := func() {
80+
conn.Close()
81+
}
82+
83+
var once sync.Once
84+
go func() {
85+
io.Copy(os.Stdout, conn)
86+
once.Do(close)
87+
}()
88+
io.Copy(conn, os.Stdin)
89+
once.Do(close)
90+
91+
log.Debug("Exiting snetcat...")
8792
}
88-
89-

netcat/utils/quicconn.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
package utils
22

33
import (
4-
"time"
5-
"net"
6-
7-
quic "github.com/lucas-clemente/quic-go"
4+
"net"
5+
"time"
6+
7+
quic "github.com/lucas-clemente/quic-go"
88
)
99

1010
type QuicConn struct {
11-
Session quic.Session
12-
Stream quic.Stream
11+
Session quic.Session
12+
Stream quic.Stream
1313
}
1414

15-
func (mc *QuicConn)Read(b []byte) (n int, err error) {
16-
return mc.Stream.Read(b)
15+
func (mc *QuicConn) Read(b []byte) (n int, err error) {
16+
return mc.Stream.Read(b)
1717
}
1818

1919
func (mc *QuicConn) Write(b []byte) (n int, err error) {
20-
return mc.Stream.Write(b)
20+
return mc.Stream.Write(b)
2121
}
2222

2323
func (mc *QuicConn) Close() error {
24-
return mc.Stream.Close()
24+
return mc.Stream.Close()
2525
}
2626

2727
func (mc *QuicConn) LocalAddr() net.Addr {
28-
return mc.Session.LocalAddr()
28+
return mc.Session.LocalAddr()
2929
}
3030

3131
func (mc *QuicConn) RemoteAddr() net.Addr {
32-
return mc.Session.RemoteAddr()
32+
return mc.Session.RemoteAddr()
3333
}
3434

3535
func (mc *QuicConn) SetDeadline(t time.Time) error {
36-
return mc.Stream.SetDeadline(t)
36+
return mc.Stream.SetDeadline(t)
3737
}
3838

3939
func (mc *QuicConn) SetReadDeadline(t time.Time) error {
40-
return mc.Stream.SetReadDeadline(t)
40+
return mc.Stream.SetReadDeadline(t)
4141
}
4242

4343
func (mc *QuicConn) SetWriteDeadline(t time.Time) error {
44-
return mc.Stream.SetWriteDeadline(t)
45-
}
44+
return mc.Stream.SetWriteDeadline(t)
45+
}

netcat/utils/scionutils.go

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package utils
22

33
import (
4-
"fmt"
5-
"regexp"
4+
"fmt"
5+
"regexp"
66

7-
"github.com/lucas-clemente/quic-go"
7+
"github.com/lucas-clemente/quic-go"
88

9-
"github.com/scionproto/scion/go/lib/snet"
10-
"github.com/scionproto/scion/go/lib/snet/squic"
11-
"github.com/scionproto/scion/go/lib/sciond"
9+
"github.com/scionproto/scion/go/lib/sciond"
10+
"github.com/scionproto/scion/go/lib/snet"
11+
"github.com/scionproto/scion/go/lib/snet/squic"
1212

13-
"github.com/netsec-ethz/scion-apps/lib/scionutil"
13+
"github.com/netsec-ethz/scion-apps/lib/scionutil"
1414
)
1515

1616
var addressPortSplitRegex, _ = regexp.Compile(`(.*,\[.*\]):(\d+)`)
@@ -19,10 +19,10 @@ func InitSCION(tlsKeyFile, tlsCertFile string, useIASCIONDPath bool) error {
1919
localCCAddr, err := scionutil.GetLocalhost()
2020
if err != nil {
2121
return err
22-
}
23-
22+
}
23+
2424
sciondPath := sciond.GetDefaultSCIONDPath(nil)
25-
if (useIASCIONDPath) {
25+
if useIASCIONDPath {
2626
sciondPath = sciond.GetDefaultSCIONDPath(&localCCAddr.IA)
2727
}
2828

@@ -31,61 +31,59 @@ func InitSCION(tlsKeyFile, tlsCertFile string, useIASCIONDPath bool) error {
3131
return err
3232
}
3333

34-
if tlsKeyFile != "" || tlsCertFile != "" {
35-
err = squic.Init(tlsKeyFile, tlsCertFile)
36-
if err != nil {
37-
return err
38-
}
39-
}
34+
if tlsKeyFile != "" || tlsCertFile != "" {
35+
err = squic.Init(tlsKeyFile, tlsCertFile)
36+
if err != nil {
37+
return err
38+
}
39+
}
4040

4141
return nil
4242
}
4343

44-
4544
func DialSCION(remoteAddress string) (*QuicConn, error) {
46-
localCCAddr, err := scionutil.GetLocalhost()
47-
if err != nil {
48-
return nil, err
49-
}
50-
51-
remoteCCAddr, err := snet.AddrFromString(remoteAddress)
52-
if err != nil {
53-
return nil, err
54-
}
55-
56-
quicConfig := &quic.Config {
57-
KeepAlive: true,
58-
}
59-
60-
sess, err := squic.DialSCION(nil, localCCAddr, remoteCCAddr, quicConfig)
61-
if err != nil {
62-
return nil, err
63-
}
64-
65-
stream, err := sess.OpenStreamSync()
66-
if err != nil {
67-
return nil, err
68-
}
69-
70-
return &QuicConn{Session:sess, Stream:stream}, nil
45+
localCCAddr, err := scionutil.GetLocalhost()
46+
if err != nil {
47+
return nil, err
48+
}
49+
50+
remoteCCAddr, err := snet.AddrFromString(remoteAddress)
51+
if err != nil {
52+
return nil, err
53+
}
54+
55+
quicConfig := &quic.Config{
56+
KeepAlive: true,
57+
}
58+
59+
sess, err := squic.DialSCION(nil, localCCAddr, remoteCCAddr, quicConfig)
60+
if err != nil {
61+
return nil, err
62+
}
63+
64+
stream, err := sess.OpenStreamSync()
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
return &QuicConn{Session: sess, Stream: stream}, nil
7170
}
7271

7372
func ListenSCION(port uint16) (quic.Listener, error) {
74-
localAddress, err := scionutil.GetLocalhostString()
75-
if err != nil {
76-
return nil, err
77-
}
78-
79-
localCCAddr, err := snet.AddrFromString(fmt.Sprintf("%s:%v", localAddress, port))
80-
if err != nil {
81-
return nil, err
82-
}
83-
84-
listener, err := squic.ListenSCION(nil, localCCAddr, nil)
85-
if err != nil {
86-
return nil, err
87-
}
88-
89-
return listener, nil
90-
}
73+
localAddress, err := scionutil.GetLocalhostString()
74+
if err != nil {
75+
return nil, err
76+
}
9177

78+
localCCAddr, err := snet.AddrFromString(fmt.Sprintf("%s:%v", localAddress, port))
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
listener, err := squic.ListenSCION(nil, localCCAddr, nil)
84+
if err != nil {
85+
return nil, err
86+
}
87+
88+
return listener, nil
89+
}

0 commit comments

Comments
 (0)