func ListenForConnections(lnClient *lndwrapper.Lnd, port string, db *DB) {
	ln, err := net.Listen("tcp", ":"+port)
	if err != nil {
		log.Println(err)
	}

	log.Println("Listening on port", port)

	for {
		conn, err := ln.Accept()
		if err != nil {
			log.Println(err)
		} else {
			log.Println("Accepted new connection from:" + conn.RemoteAddr().String())

			connType := readConnectionType(conn)

			if connType == peerConn {

				log.Println("Peer Connection, accepting handshake...")
				sessionKey, baseIV, startSeq, lightningPeerPubKey := acceptPeerHandshake(conn, lnClient, db)
				log.Println("Peer Handshake successful")

				//Handle the connection
				go handlePeerConnection(conn, lnClient, db, sessionKey, baseIV, startSeq, lightningPeerPubKey)

			} else if connType == destinationConn {
				//Read connecting token and save connection in the Database
				routeTokenBytes := make([]byte, 10)
				_, err = conn.Read(routeTokenBytes)
				if err != nil {
					log.Println(err)
				}
				routeToken := string(routeTokenBytes)
				db.addDestConnToDB(routeToken, &connInfo{conn: conn})
			} else {
				log.Println("Unknown connection type")
			}

		}
	}
}
//ListenForConnections listens to new nodes that want to connect and accepts them
ListenForConnections listens to new nodes that want to connect and accepts them
// ListenForConnections listens to new nodes that want to connect and accepts them
func ListenForConnections(lnClient *lndwrapper.Lnd, port string, db *DB) {
	ln, err := net.Listen("tcp", ":"+port)
	if err != nil {
		log.Println(err)
	}
	log.Println("Listening on port", port)
	for {
		conn, err := ln.Accept()
		if err != nil {
			log.Println(err)
		} else {
			log.Println("Accepted new connection from:" + conn.RemoteAddr().String())
			connType := readConnectionType(conn)
			if connType == peerConn {
				log.Println("Peer Connection, accepting handshake...")
				sessionKey, baseIV, startSeq, lightningPeerPubKey := acceptPeerHandshake(conn, lnClient, db)
				log.Println("Peer Handshake successful")
				go handlePeerConnection(conn, lnClient, db, sessionKey, baseIV, startSeq, lightningPeerPubKey)
			} else if connType == destinationConn {
				routeTokenBytes := make([]byte, 10)
				_, err = conn.Read(routeTokenBytes)
				if err != nil {
					log.Println(err)
				}
				routeToken := string(routeTokenBytes)
				db.addDestConnToDB(routeToken, &connInfo{conn: conn})
			} else {
				log.Println("Unknown connection type")
			}
		}
	}
}
func ListenForConnections ( lnClient * lndwrapper . Lnd , port string , db * DB ) { ln , err := net . Listen ( " " , " " + port ) if err != nil { log . Println ( err ) } log . Println ( " " , port ) for { conn , err := ln . Accept ( ) if err != nil { log . Println ( err ) } else { log . Println ( " " + conn . RemoteAddr ( ) . String ( ) ) connType := readConnectionType ( conn ) if connType == peerConn { log . Println ( " " ) sessionKey , baseIV , startSeq , lightningPeerPubKey := acceptPeerHandshake ( conn , lnClient , db ) log . Println ( " " ) go handlePeerConnection ( conn , lnClient , db , sessionKey , baseIV , startSeq , lightningPeerPubKey ) } else if connType == destinationConn { routeTokenBytes := make ( [ ] byte , 10 ) _ , err = conn . Read ( routeTokenBytes ) if err != nil { log . Println ( err ) } routeToken := string ( routeTokenBytes ) db . addDestConnToDB ( routeToken , & connInfo { conn : conn } ) } else { log . Println ( " " ) } } } }
ListenForConnections listens to new nodes that want to connect and accepts them
ListenForConnections listens to new nodes that want to connect and accepts them
//Handle the connection //Read connecting token and save connection in the Database