Fixes
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@@ -14,12 +15,12 @@ import (
|
|||||||
|
|
||||||
func tcpLinker() {
|
func tcpLinker() {
|
||||||
links, err := parseConf()
|
links, err := parseConf()
|
||||||
if links == nil {
|
if err != nil {
|
||||||
log.Println("No values in config file or file not present (/etc/darkstorm-server.conf). tcp linker signing off")
|
log.Println("Error while trying to parse config file:", err, "tcp linker signing off")
|
||||||
quitChan <- "tcp conf"
|
quitChan <- "tcp conf"
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if links == nil {
|
||||||
log.Println("Error while trying to parse config file:", err)
|
log.Println("No values in config file or file not present (/etc/darkstorm-server.conf). tcp linker signing off")
|
||||||
quitChan <- "tcp conf"
|
quitChan <- "tcp conf"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -58,36 +59,22 @@ failWaiting:
|
|||||||
|
|
||||||
func link(port int, addr string, failChan chan int) {
|
func link(port int, addr string, failChan chan int) {
|
||||||
listen, err := net.Listen("tcp", ":"+strconv.Itoa(port))
|
listen, err := net.Listen("tcp", ":"+strconv.Itoa(port))
|
||||||
defer listen.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error while trying to listen to port ", port, ":", err)
|
log.Println("Error while trying to listen to port ", port, ":", err)
|
||||||
failChan <- port
|
failChan <- port
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer listen.Close()
|
||||||
for {
|
for {
|
||||||
con, err := listen.Accept()
|
con, err := listen.Accept()
|
||||||
defer con.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error while trying to accept connection to port ", port, ":", err)
|
log.Println("Error while trying to accept connection to port ", port, ":", err)
|
||||||
failChan <- port
|
failChan <- port
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ext, err := net.Dial("tcp", addr)
|
err = copyConn(con, addr)
|
||||||
defer ext.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error while trying to dial", addr, ":", err)
|
log.Println("Error while trying copy data from port", port, "to address", addr, ":", err)
|
||||||
failChan <- port
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = io.Copy(ext, con)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error while trying to copy data to", addr, ":", err)
|
|
||||||
failChan <- port
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = io.Copy(con, ext)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error while trying to copy data to port", port, ":", err)
|
|
||||||
failChan <- port
|
failChan <- port
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -97,7 +84,10 @@ func link(port int, addr string, failChan chan int) {
|
|||||||
func parseConf() (links map[int]string, err error) {
|
func parseConf() (links map[int]string, err error) {
|
||||||
conf, err := os.Open("/etc/darkstorm-server.conf")
|
conf, err := os.Open("/etc/darkstorm-server.conf")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
fmt.Println("HII")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
lineNum := 0
|
lineNum := 0
|
||||||
links = make(map[int]string)
|
links = make(map[int]string)
|
||||||
@@ -106,8 +96,10 @@ func parseConf() (links map[int]string, err error) {
|
|||||||
lineNum++
|
lineNum++
|
||||||
var origLine string
|
var origLine string
|
||||||
origLine, err = rdr.ReadString('\n')
|
origLine, err = rdr.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil && origLine == "" {
|
||||||
break
|
break
|
||||||
|
} else if origLine == "" {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
line := strings.ReplaceAll(origLine, "\t", " ")
|
line := strings.ReplaceAll(origLine, "\t", " ")
|
||||||
for strings.Contains(line, " ") {
|
for strings.Contains(line, " ") {
|
||||||
@@ -129,8 +121,36 @@ func parseConf() (links map[int]string, err error) {
|
|||||||
links[i] = split[1]
|
links[i] = split[1]
|
||||||
}
|
}
|
||||||
err = nil
|
err = nil
|
||||||
if len(links) > 0 {
|
if len(links) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyConn(src net.Conn, addr string) error {
|
||||||
|
dst, err := net.Dial("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Erro while dialing", addr)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer src.Close()
|
||||||
|
defer dst.Close()
|
||||||
|
io.Copy(dst, src)
|
||||||
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer src.Close()
|
||||||
|
defer dst.Close()
|
||||||
|
io.Copy(src, dst)
|
||||||
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-done
|
||||||
|
<-done
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user