|
@@ -26,8 +26,10 @@ import (
|
|
type ServerMessageBlockFileSystemAbstraction struct {
|
|
type ServerMessageBlockFileSystemAbstraction struct {
|
|
UUID string
|
|
UUID string
|
|
Hierarchy string
|
|
Hierarchy string
|
|
|
|
+ root string
|
|
ipaddr string
|
|
ipaddr string
|
|
user string
|
|
user string
|
|
|
|
+ pass string
|
|
conn *net.Conn
|
|
conn *net.Conn
|
|
session *smb2.Session
|
|
session *smb2.Session
|
|
share *smb2.Share
|
|
share *smb2.Share
|
|
@@ -62,16 +64,43 @@ func NewServerMessageBlockFileSystemAbstraction(uuid string, hierarchy string, i
|
|
return ServerMessageBlockFileSystemAbstraction{}, err
|
|
return ServerMessageBlockFileSystemAbstraction{}, err
|
|
}
|
|
}
|
|
|
|
|
|
- log.Println("[SMB-FS] Connected to remote: " + ipaddr)
|
|
|
|
- return ServerMessageBlockFileSystemAbstraction{
|
|
|
|
|
|
+ fsAbstraction := ServerMessageBlockFileSystemAbstraction{
|
|
UUID: uuid,
|
|
UUID: uuid,
|
|
Hierarchy: hierarchy,
|
|
Hierarchy: hierarchy,
|
|
|
|
+ root: rootShare,
|
|
ipaddr: ipaddr,
|
|
ipaddr: ipaddr,
|
|
user: username,
|
|
user: username,
|
|
|
|
+ pass: password,
|
|
conn: &conn,
|
|
conn: &conn,
|
|
session: s,
|
|
session: s,
|
|
share: fs,
|
|
share: fs,
|
|
- }, nil
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Create a ticker to check for renewing conncetion once an hour
|
|
|
|
+ ticker := time.NewTicker(1 * time.Hour)
|
|
|
|
+ done := make(chan bool)
|
|
|
|
+ go func(s *ServerMessageBlockFileSystemAbstraction) {
|
|
|
|
+ for {
|
|
|
|
+ select {
|
|
|
|
+ case <-done:
|
|
|
|
+ return
|
|
|
|
+ case <-ticker.C:
|
|
|
|
+ //Unable to list share due to session timeout. Close the handler and try connecting again.
|
|
|
|
+ s.share.Umount()
|
|
|
|
+ time.Sleep(300 * time.Millisecond)
|
|
|
|
+ fs, err := s.session.Mount(s.root)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("[SMBFS] Unable to remount " + s.root)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ fmt.Println("[SMBFS] Session Renewed for " + s.root)
|
|
|
|
+ s.share = fs
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }(&fsAbstraction)
|
|
|
|
+
|
|
|
|
+ log.Println("[SMB-FS] Connected to remote: " + ipaddr)
|
|
|
|
+ return fsAbstraction, nil
|
|
}
|
|
}
|
|
|
|
|
|
func (a ServerMessageBlockFileSystemAbstraction) Chmod(filename string, mode os.FileMode) error {
|
|
func (a ServerMessageBlockFileSystemAbstraction) Chmod(filename string, mode os.FileMode) error {
|