-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luca Bassi
committed
Apr 11, 2024
1 parent
bb5aa0a
commit 1f00729
Showing
22 changed files
with
340 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/org/italiangrid/storm/webdav/tpc/SciTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.tpc; | ||
|
||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SciTag { | ||
|
||
public static final Logger LOG = LoggerFactory.getLogger(SciTag.class); | ||
|
||
private final String flowdPipeName = "/var/run/flowd"; | ||
private final int experimentId; | ||
private final int activityId; | ||
private String localAddress; | ||
private int localPort; | ||
private String remoteAddress; | ||
private int remotePort; | ||
|
||
public SciTag(int experimentId, int activityId) { | ||
this.experimentId = experimentId; | ||
this.activityId = activityId; | ||
} | ||
|
||
public int activityId() { | ||
return activityId; | ||
} | ||
|
||
public int experimentId() { | ||
return experimentId; | ||
} | ||
|
||
private String flowdEntry() { | ||
return " tcp " + localAddress + " " + localPort + " " + remoteAddress + " " + remotePort + " " | ||
+ this.experimentId() + " " + this.activityId() + "\n"; | ||
} | ||
|
||
public void writeStart(String localAddress, int localPort, String remoteAddress, int remotePort) { | ||
this.localAddress = localAddress; | ||
this.localPort = localPort; | ||
this.remoteAddress = remoteAddress; | ||
this.remotePort = remotePort; | ||
try { | ||
RandomAccessFile flowdPipe = new RandomAccessFile(flowdPipeName, "rw"); | ||
flowdPipe.writeBytes("start" + this.flowdEntry()); | ||
} catch (IOException e) { | ||
LOG.warn(e.getMessage(), e); | ||
} | ||
} | ||
|
||
public void writeEnd() { | ||
try { | ||
RandomAccessFile flowdPipe = new RandomAccessFile(flowdPipeName, "rw"); | ||
flowdPipe.writeBytes("end" + this.flowdEntry()); | ||
} catch (IOException e) { | ||
LOG.warn(e.getMessage(), e); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/italiangrid/storm/webdav/tpc/SciTagPlainConnectionSocketFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.tpc; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.Socket; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.conn.socket.PlainConnectionSocketFactory; | ||
import org.apache.http.protocol.HttpContext; | ||
import org.italiangrid.storm.webdav.tpc.SciTag; | ||
|
||
public class SciTagPlainConnectionSocketFactory extends PlainConnectionSocketFactory { | ||
|
||
public SciTagPlainConnectionSocketFactory() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public Socket connectSocket(int connectTimeout, Socket socket, HttpHost host, | ||
InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) | ||
throws IOException { | ||
Socket s = | ||
super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context); | ||
SciTag scitag = (SciTag) context.getAttribute("scitag"); | ||
if (scitag != null) { | ||
String localIPAddress = s.getLocalAddress().getHostAddress(); | ||
int localPort = s.getLocalPort(); | ||
String remoteIPAddress = s.getInetAddress().getHostAddress(); | ||
int remotePort = s.getPort(); | ||
scitag.writeStart(localIPAddress, localPort, remoteIPAddress, remotePort); | ||
} | ||
return s; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/org/italiangrid/storm/webdav/tpc/SciTagSSLConnectionSocketFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.tpc; | ||
|
||
import java.io.IOException; | ||
import java.net.Socket; | ||
import javax.net.ssl.SSLContext; | ||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||
import org.apache.http.protocol.HttpContext; | ||
import org.italiangrid.storm.webdav.tpc.SciTag; | ||
|
||
public class SciTagSSLConnectionSocketFactory extends SSLConnectionSocketFactory { | ||
|
||
public SciTagSSLConnectionSocketFactory(SSLContext sslContext) { | ||
super(sslContext); | ||
} | ||
|
||
@Override | ||
public Socket createLayeredSocket(Socket socket, String target, int port, HttpContext context) | ||
throws IOException { | ||
Socket s = super.createLayeredSocket(socket, target, port, context); | ||
SciTag scitag = (SciTag) context.getAttribute("scitag"); | ||
if (scitag != null) { | ||
String localIPAddress = s.getLocalAddress().getHostAddress(); | ||
int localPort = s.getLocalPort(); | ||
String remoteIPAddress = s.getInetAddress().getHostAddress(); | ||
int remotePort = s.getPort(); | ||
scitag.writeStart(localIPAddress, localPort, remoteIPAddress, remotePort); | ||
} | ||
return s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.